首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
8sif120编程辅导、辅导C/C++程序
项目预算:
开发周期:
发布时间:
要求地区:
Architecture and Network Programming
8sif120
Lab #1 (due date : Oct 10th 2020) Paul Girard, Ph.D.
Objective
Implement the FTP "put" function ==> put local_file_name remote_ file_name
using the client-server concept and the TCP socket functions. The put function will
support an ASCII file transfer from the client to the server. Each message will be a
logical record read from a local text file and send through a tcp socket to the server until
the end of file (test feof on local_file).
Methodology
1. Login on dim-ensxcn1.uqac.ca using putty; specify your user account and password.
(see Appendix C)
- copy the following 4 files with the command cp to the server dim-ensxcn1.uqac.ca
$ cp ../web00300/client_base.c .
$ cp ../web00300/compbasec .
$ cp ../web00300/tp2dat1 .
$ cp ../web00300/tp2dat3 .
- Do a login on dim-ensxcn2.uqac.ca and copy the following 2 files to this server
$ cp ../web00300/server_base.c .
$ cp ../web00300/compbases .
2. Use EditPlus to open source (.c) file locally and save them locally (USB key or hard
disk).
3. Change the protection of compbasec and compbases to be executable on each server
$ chmod 700 compbasec
$ chmod 700 compbases
4. Compile each program client_base.c and server_base.c with the previous command
files on each server :
(dim-ensxcn1) $ ./compbasec
(dim-ensxcn2) $ ./compbases
5. Now execute these 2 programs in the following order. The output should be the same
as shown in Appendix A
on dim-ensxcn2: $ ./server_base 5xxx (xxx are the 3 last digits of your userid on dimensxcn2.uqac.ca
[web00xxx])
on dim-ensxcn1: $ ./client_base dim-ensxcn2.uqac.ca 5xxx
remark: Use Ctl C to kill the server process1 when the execution is completed
1 The unix command netstat -a displays all sockets used and their status
8sif120/lab1 ©Paul Girard Ph.D. page 2 of 9
5. - Now that you know how to execute these basic programs rename each one with the
Unix command mv
client_base.c ===> client_ftp.c
server_base.c ===> server_ftp.c
(ex. mv client_base.c client_ftp.c)
- Create the two new compilation procedures for these 2 programs with EditPlus
[web00***@dim-ensxcn1]$ more complab1c
gcc client_ftp.c -lnsl -lrt -o client_ftp
[web00***@dim-ensxcn2]$ more complab1s
gcc server_ftp.c -o server_ftp
6. Read the code of each client and server base programs to understand
the protocol and the timing of execution.
Then modify the program client_ftp.c to transfer an ASCII file to the server
- Delete the code for the 1 second delay (sleep) and the actual DATA message.
- The program waits from keyboard a command line the having 3 parameters (only put
is supported):
put local_filename remote_filename
DO NOT ENTER THIS COMMAND USING 3 scanf, IT MUST BE ENTERED
USING A SINGLE LINE.
After a successful opening (read mode) of the local file, the extracted remote file name
will be transmitted to the server. The client program will then wait until it receives the
message "ACK" from the server; this message will be transmitted by the server as
soon as the server will open successfully (write mode) the file whose name has been
transmitted by the client (remote_file). Display a short message specifying that the
server is now ready to receive the file local_file. If the server was not able to open this
file in a write mode, a "NAK" message will be sent to the client which will close the
socket. The client will then have to reconnect and request a new remote file name.
- The client will then read the Unix timer with the function clock_gettime() which
returns the current high-resolution in real time. Time is expressed in seconds AND
nanoseconds since some arbitrary time in the past. Each logical record of the local file
will then be read and transmitted immediately to the server; each record read by the
server will be written in its own file. A message from the client to the server
contains only one logical record and not the complete file. The timer will be read a
second time after the end of file in order to calculate the transfer delay in milliseconds
and the transfer rate in Koctets/second. The number of logical records read will be
displayed and the number of octets transfered. The delay is the time just before calling
connect() and immediately after the close() of the socket.
8sif120/lab1 ©Paul Girard Ph.D. page 3 of 9
Example using clock_gettime ()
struct timespec time1, time2, temp; /* time_t tv_sec; seconds
long tv_nsec; nanoseconds */
double delay;
...
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); /* read the timer1 nanosec*/
... ==> file transfer where lines sent and octets sent are saved
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); /*read the timer2 in nanosec*/
/* Statistics */
if ((time2.tv_nsec-time1.tv_nsec)<0)
{
temp.tv_sec = time2.tv_sec-time1.tv_sec-1;
temp.tv_nsec = 1000000000+time2.tv_nsec-time1.tv_nsec;
} else
{
temp.tv_sec = time2.tv_sec-time1.tv_sec;
temp.tv_nsec = time2.tv_nsec-time1.tv_nsec;
};
delay = (double)((temp.tv_sec * 1000000) + (temp.tv_nsec/1000)); /* delay in microsec*/
delay = (double)delay/1000; /* delay in msec */
printf("File %s had %d lines and a total of %d octets\n",filename_local, nline, noctets);
printf("Transfer rate : %9.3f MO/sec \t Transfer delay:%9.3f msec\n",
(double)((noctets*0.9765)/(1024*delay)),delay);
- The client will close its socket and the file. A message "End of program" will be
displayed on the screen.
- You should use the following functions in the client program :
fgets(buf, 81, fptr) to read a logical record of the file,
fclose(fptr) to close the file.
feof(fptr) to test the end of file
- Each file tp2dat* (do not change the content or the name) will be opened in a read
mode by the client program. The following example shows how to read a file name on
the terminal and open it in a read mode.
8sif120/lab1 ©Paul Girard Ph.D. page 4 of 9
FILE *fptr; /*pointer to file descriptor*/
char filename[20];
char buf[81]; /* buffer */
.......
puts("Name of the file to transmit ? ");
gets(filename);
if ((fptr = fopen(filename, "r")) == NULL)
{
perror("error opening this file");
exit (0);
}
...
while (fgets(buf, 81, fptr)); /* read a file record */
{
...
}
10. Modify the program server _ftp.c receiving an ascii text file from the client :
- Modify the actual DATA message for "ACK" and create another DATA message
“NAK”
- The server must never stop. When a client connection is accepted, the server displays
a message like "Connection accepted". The server will then wait for a message from the
client. After a successful connection from a client, the server read the name of a new
file to be received later by the client. The server will display this file name. If this file
is successfully opened in a write mode, the server will then send an ACK message to the
client. If the client receives this ACK, it will begin the transmission of a series of
message (one message/logical record). If the server cannot open the file in a write mode
a NAK will be transmitted to the client and the server will go back in a listening mode
(accept) after printing a message. If the ACK has been transmitted, the server will read
each message from the client and write each logical record to the file opened in a write
mode. At the end of transmission, the server will display the number of received octets.
This number should correspond to the number of octets sent by the client (and the size
of this file on the operating system with the Unix command ls -ls).
8sif120/lab1 ©Paul Girard Ph.D. page 5 of 9
Client - Server Synchronization
1. The server waits for a client connection
2. The client reads the command line
“put local_file_name remote_file_name”.
it opens the local file,
if successful, it does a connect to the server
and if successful, it transmits the name of
the remote file to the server and waits ====>
3. The server receives the file name & opens it
in a write mode. If successful, it transmits an
ACK to the client , if not then a NAK will be
transmitted and the server closes the client
connection and returns to a wait state (step 1.)
<=====
4. The client receives and validate the
ACK/NAK.
If it is a NAK, a message is printed
by the client and then exit
If it is an ACK, a logical record is read
from the file and sent to the server.
=====> 5. The server receives the message and write a
logical record to its file and waits for the next
message until the end of transmission.
6. Each record is read and sent to the server
until feof(). At the end, it closes the socket
and the file. =====> 7. When the client socket is closed TCP sends
an end of connection to the server. The server
then closes the client connection, closes the
file and waits for another client connection
(step 1)
- The following functions should be used by the server :
fputs(buf, fptr) to write a logical record in a file,
fclose(fptr) to close the file.
Example of a file creation
FILE *fptr;
char buf[81];
char filename[20];
.......
the filename is transmitted by client_ftp
if ((fptr = fopen(filename, "w")) == NULL);
{ perror("error opening this file");
exit (0);
}
...
fputs(buf, fptr); /* write a record to a file */
8sif120/lab1 ©Paul Girard Ph.D. page 6 of 9
Lab report
Verify the output of client_ftp and server_ftp in Appendix B before doing your final
report (one report for one team). The report will have the following components.
1) The name of each team member and their student code, the userid and password
to test it
2) The list of each source program (client_ftp.c and server_ftp.c) ; do not change the
name of these programs. DO NOT MODIFY THE ACTUAL COMMENTS.
3) An example of execution showing the two original file transfers (tp2dat1 et tp2dat3)
by copying each line for the client and the server telnet session. Do the command ls –ls
to show the size of your files. DO NOT MODIFY THOSE FILES.
4) DO NOT COPY AN EXAMPLE FROM THE INTERNET ==> 0
Print and give the report to the assistant professor before due date. Do not forget to give
your userid, your password and the name of the subdirectory if you created one. We
must be able to execute your programs and display the source.
8sif120/lab1 ©Paul Girard Ph.D. page 7 of 9
Appendix A
Execution of server_base
(SSH #1 with dim-ensxcn2.uqac.ca)
[pgirard@dim-ensxcn2 tut_sif120]$ ./compbases
[pgirard@dim-ensxcn2 tut_sif120]$ ./server_base 5001
The port number used by the tcp socket is #5001
server ready for connection
Client connection
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
=====>Dummy message from client to the server using tcp
End of client connection
Execution of client_base
(executed after server_base using SSH #2 with dim-ensxcn1)
[pgirard@dim-ensxcn1 tut_sif120]$ ./compbasec
[pgirard@dim-ensxcn1 tut_sif120]$ ./client_base dim-ensxcn2 5001
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
===> Dummy message from server : acknowledge client message
End of client program
[pgirard@dim-ensxcn1 tut_sif120]$
8sif120/lab1 ©Paul Girard Ph.D. page 8 of 9
Appendix B
Execution of server_ftp with 2 requests
(telnet #1 on dim-ensxcn2)
[pgirard@dim-ensxcn2 tut_sif120]$ ./server_ftp 5001
The tcp socket port number is #5001
Server ready for connections
Client connection
=====>test3
End of client file transfer
File test3 has 87969 octets
Client connection
=====>test1
End of client file transfer
File test1 has 1497 octets
Execution of client_ftp (3 exec)
(telnet #2 on dim-ensxcn1)
[pgirard@dim-ensxcn1 tut_sif120]$ ./client_ftp dim-ensxcn2.uqac.ca 5001
myftp> put tp2dat3 test3
ftp command=> put local file=> tp2dat3 remote file=> test3
File tp2dat3 had 1100 lines and a total of 87969 octets
Transfer rate : 43.086 MO/sec Transfer delay: 1.947 msec
End of program
[pgirard@dim-ensxcn1 tut_sif120]$ ./client_ftp dim-ensxcn2.uqac.ca 5001
myftp> put tp2dat1 test1
ftp command=> put local file=> tp2dat1 remote file=> test1
File tp2dat1 had 56 lines and a total of 1497 octets
Transfer rate : 11.513 MO/sec Transfer delay: 0.124 msec
End of program
8sif120/lab1 ©Paul Girard Ph.D. page 9 of 9
Appendix C
Examples of C functions used in lab 1
1) scanf : used to read string (s) on the keyboard
2) strcmp : used to compare 2 strings
For example, the following instructions read a filename and a file type. We accept only
the text file type . If this not a text file, print an error message and exit.
char type[16]; /* file type */
char filename [20]; /* name of a file */
...
printf("Please enter the file name and the file type > ");
scanf("%s %s ", filename, type); /* read the filename and the file type on the
keyboard /*
if (strcmp(type,"text") != 0) /* if type is not text then error and exit */
{
printf("Error : the file type %s is not supported \n", type);
return 1;
}
...
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写 gr5280、代做 java/pytho...
2024-12-22
代写 data 编程、代做 python ...
2024-12-22
chc5049 代做、代写 sql 编程设...
2024-12-22
comp1038 代写、c++编程设计代...
2024-12-22
chc5028代做、代写c/c++设计编...
2024-12-21
代做program、代写sql程序设计
2024-12-21
itc228编程代写、代做java程序...
2024-12-21
代写comp 330 (fall 2024): as...
2024-12-21
代写busi2105 quantitative me...
2024-12-21
代做7ssgn110 environmental d...
2024-12-21
代做busi2105 quantitative me...
2024-12-21
代写csc 110 y1f fall 2024 qu...
2024-12-21
代做management accounting au...
2024-12-21
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!