The UDP client/server will likely be helpful as a starting place for this assignment (the TCP client/server will likely not be helpful). You may use any piece of this code in your own programs.
Also we have provided some sample output files:
server 32000
client 128.111.52.10 32000
+--------------+--------------+-----------------------------+ | Packet Type | Reserved | Sequence Number | +--------------+--------------+-----------------------------+
NOTE: The packet header should be treated as one 32 bit word that is included as the first 32 bits of the transmitted/received message. You will need to make sure you can send the bits accurately.
The handling of each packet type is described as follows.
----------------------------------------------------------------------- Packet Type = 0 (Ping Request) Client input: PING Client output: PING request sent, waiting for response... Server output: PING request received. Client output on timeout: PING response not received. Client Action ------------- Can only be initiated by a client. Sent to server (with a valid sequence number) to test liveness. When sent, start a timer for one second. If timeout occurs before receiving a response, report timeout to user. Server Action ------------- Upon receiving a Ping Request, a server should respond immediately with a Ping Response. There is no time when a Ping Request cannot be issued, i.e. it is valid to send a Ping Request even if there is not a connection between the client and server. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 1 (Ping Response) Client input: N/A Client output: PING response received. Server output: PING response sent. Client output if PING request was NOT sent: PING response received... but NO PING request sent. Client Action ------------- Receive packet, validate against outstanding PING request (using sequence number) and display message. Server Action ------------- Upon receiving a Ping Request, a server should respond immediately with a Ping Response. Response should contain the Request packet's sequence number. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 5 (First Message) Client input: <client message> (assuming it is FIRST MESSAGE SENT) Client output: SENDING FIRST MESSAGE: "<client message>" Server output: RECEIVED FIRST MESSAGE: "<client message>" Example: <client message> = Hello world Client output: SENDING FIRST MESSAGE: "Hello world" Client Action ------------- For first message, choose starting sequence number as a random number between 0 and 2^(16)-1. Subsequent messages should increment sequence number by 1. Client must handle sequence wrap properly. Message limit is 80 bytes. Start timer with one second delay. If no response received display the following message: FIRST MESSAGE: "<client message>" NOT RECEIVED, TRYING AGAIN... Pick new random sequence number and try again. Attempt three times. If no response, send Reset (packet type=97), and exit. Server Action ------------- Upon receiving a message, server should respond immediately with the message REVERSED. If a First Message packet has already been received, server should respond with an Invalid Control Sequence packet (packet type=98) Server must handle sequence wrap properly. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 6 (Standard Message) Client input: <client message> Client output: SENDING MESSAGE: "<client message>" Server output: RECEIVED MESSAGE: "<client message>" Client Action ------------- Increment sequence number and send message. Start timer with one second delay. If no response received display the following message: MESSAGE: "<client message>" NOT RECEIVED Take no further action with regard to this message. Server Action ------------- Upon receiving a message, server should respond immediately with the message REVERSED. If a message is received with an unexpected sequence number, server should respond with Packet Type = 11. After displaying server output as required (see above), server should also display the following message: MESSAGE RECEIVED AND PROCESSED WITH UNEXPECTED SEQUENCE NUMBER -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 7 (Last Message) Client input: END TRANSMISSION Client output: SENDING END-OF-TRANSMISSION Server output: RECEIVED END-OF-TRANSMISSION Client Action ------------- When client input matches the End Transmission string, first increment sequence number then send packet type=7. Start timer with one second delay. If no response received display: END-OF-TRANSMISSION NOT RECEIVED, TRYING AGAIN... Attempt three times. If no response, send Reset (packet type=97), and exit. Server Action ------------- Upon receiving a Last Message packet, server should respond with packet type=12. If a Last Message packet is received with an unexpected sequence number, server should respond with Packet Type = 12. After displaying server output as required (see above), server should also display the following message: LAST MESSAGE RECEIVED AND PROCESSED WITH UNEXPECTED SEQUENCE NUMBER If a Last Message packet is received and there is no valid connection, server should immediately send an Invalid Control Sequence packet (packet type=98). -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 10 (Standard Response) Client input: N/A Client output: REVERSED MESSAGE: "<reversed client message>" Server output: SENDING REVERSED MESSAGE: "<reversed client message>" Client Action ------------- Receive response and display. If the client receives a sequence number that is not expected, it should also display the following message (after displaying the message above): RESPONSE MESSAGE RECEIVED AND PROCESSED WITH UNEXPECTED SEQUENCE NUMBER If a client receives this packet when no data was sent, it should immediately send a Reset (packet type=97), and exit. Server Action ------------- Respond with message using packet type=10 -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 11 (Out-of-Sequence Response) Client input: N/A Client output: REVERSED MESSAGE: <reversed client message> NOTIFICATION: PREVIOUS RESPONSE(S) NOT RECEIVED Server output: SENDING REVERSED MESSAGE: <reversed client message> NOTIFICATION: PREVIOUS REQUESTS(S) NOT RECEIVED Client Action ------------- Receive reversed message and display it. If the client receives a sequence number that is not expected, it should also display the following message (after displaying the message above): RESPONSE MESSAGE RECEIVED AND PROCESSED WITH UNEXPECTED SEQUENCE NUMBER If a client receives this packet when no data was sent, it should immediately send a Reset (packet type=97), and exit. Server Action ------------- Sent when server recognizes missed packets. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 12 (Last Message Response) Client input: N/A Client output: TRANSMISSION ENDED Server output: SEND END-OF-TRANSMISSION Client Action ------------- Received in response to a packet sent with a packet type=7. Action should be to close socket and exit program. If the client receives a sequence number that is not expected, it should also display the following message (after displaying the message above): RESPONSE MESSAGE RECEIVED AND PROCESSED WITH UNEXPECTED SEQUENCE NUMBER If a client receives this packet when no Last Message packet was sent, it should immediately send a Reset (packet type=97), and exit. Server Action ------------- Sent in response to packet type=7, exit. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 97 (Reset) Client input: N/A Client output: CLIENT RESETTING AND EXITING. Server output: CLIENT REQUESTS RESET. Client Action ------------- Display message and exit. Server Action ------------- Exit. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 98 (Invalid Control Sequence) Client input: N/A Client output: SERVER REPORTS INVALID CONTROL SEQUENCE Server output: INVALID CONTROL SEQUENCE IN RECEIVED MESSAGE Client Action ------------- Display message, send Reset (packet type=97), and exit. Server Action ------------- Respond with packet type=98 and the sequence number in the problem packet. This packet is sent in response to any invalid control sequence, e.g. a Standard Message before a First Message, a Standard Message after a Last Message, any sever response message (Type=1,10,11,12) from the client, etc. -----------------------------------------------------------------------
----------------------------------------------------------------------- Packet Type = 99 (Unrecognized Packet Type) Client input: N/A Client output: SERVER REPORTS UNRECOGNIZED PACKET TYPE Server output: UNRECOGNIZED PACKET TYPE IN RECEIVED MESSAGE Client Action ------------- Display message, send Reset (packet type=97), and exit. Server Action ------------- Respond with packet type=99 and the sequence number in the problem packet. -----------------------------------------------------------------------
NOTE: There is some overlap between the client and server recognizing a packet has been lost or received out of order and using a special control message. This is appropriate because different information is conveyed. Recognizing that a packet is received out of order is one thing, but then communicating that information to the peer (which is what the packet type=11 is used for) is another.
Also, your server is expected to only work with one client at a time. So, you do not need to keep information about the status of communication between the server and multiple clients.
Be sure to include a brief comment section at the beginning of these two programs that includes your name, program name, etc.
Finally, it is highly recommended that if you copied code from some reference that you include a note giving full credit to the author of the original code, and where you obtained that code.
To turn in assignments, use the following command from the Computer Science CSIL lab:
csil-machine> turnin hw2@cs176b hw2NOTE: The final "hw2" is the local directory containing the two files client.c and server.c.