CSE 3100作业代写、代做C/C++编程作业、代写TCP留学生作业、C/C++实验作业代做

CSE 3100作业代写、代做C/C++编程作业、代写TCP留学生作业、C/C++实验作业代做
CSE 3100 Systems Programming Fall 2018
Lab #7
Welcome to Lab 7! This lab assignment is due 36 hours after your lab session starts. For example,
if your lab session starts at 8am on Friday, the assignment is due at 8pm on Saturday.
Read each question carefully before beginning work. Start by executing git pull inside your Git repository
on the virtual machine. Remember to add, commit, and push when you complete your work. Add
ONLY *.c to the git repo. Do not add .o files or executables.
(100 Points) Sum server
Implement a server program that communicates with a client program via the Internet sockets. The
server listens on TCP port 3100 and has an IPv4 address. The server computes the sum of integers it receives
from the client. The protocol is described below in detail.
Protocol
The messages exchanged between the client and server are lines. Every line must end with a newline
character (’\n’). A line has at most 30 characters, including the newline character. The lines end with ’\n’
and the NUL character should not be sent. Integers are sent as strings that represent the values in decimal.
For example, 3100 is sent as four characters "3100".
A session starts when a client is connected to the server. When the connection is made, the server sends
0, the initial value of the sum, to the client. Specifically, the message the client receives is "0\n". The
client sends one integer at a time to the server and, in response, the server sends back the sum of all the
integers it has received from the client in the session so far, or an error message if the client does not follow
the protocol. To complete the session, the client sends "exit" to the server, and the server responds with
"Bye " followed by the sum.
Both the server and the client end the session if there is an error reading from/writing to the socket. The
server should detect errors in the client’s message. The error messages the server should send back to the
client are as follows.
1. "Error LongLine " followed by the current sum, if the line is too long.
2. "Error NaN " followed by the current sum, if the server fails to find an integer from the line.
Implementation
The server should listen for inbound requests to TCP port 3100 on localhost. It should be able to
communicate with multiple clients at the same time. Upon receiving a request from a client, the server
spawns a child process responsible for working with the client. Children processes are not overlaid with
another executable. The parent process should reap the dead children processes regularly.
The server can rely on sscanf() to read an integer from the line it receives. Check the return value
of sscanf()! The server should allow white spaces at the beginning of lines and extra characters after the
integer. The server should use an integer of int type to keep track of the sum and should ignore overflow.
The client gets input lines from stdin and displays the server’s response for each line to stdout. It can
check if the user input is valid, but does not have to. The client can assume that the server’s response is
a single line. If the line is too long, the client can display to stdout the complete line or only the first 30
characters.
Use the following commands to check process status and terminate processes if necessary: ps, kill, or
pkill.
Before you complete the client program, use nc localhost 3100 command to test your server. A sample
session is shown below. The first command starts the server in background. You can also run it in another
terminal.
1
$./server &
$nc localhost 3100
0
100
100
abc
Error NaN 100
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Error LL 100
exit
Bye 100
Deliverables
A Make file is provided. You should submit two C files, namely, server.c for the server, and client.c
for the server. Both files should be located in the lab7 directory.
http://www.daixie0.com/contents/13/1925.html

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/antherpythonhelper/p/9858244.html