DOC PREVIEW
UCLA COMSCI 118 - proj1

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 118 Project 1, Spring 2011TCP Ping Pong Message ExchangeDue: May 6, 2011 11:59PMApril 12, 20111 OverviewIn this project, you are being asked to write a server/client pair in ANSI C. They should be able to exchange pingpong messages. In addition, your programs should collect certain statistics as specified below. Grading of yourcode will require it to compile using gcc on the SEASnet machines (ugrad or grad.seas.ucla.edu).In this project, a ping pong session will be initiated by a user request from your client code. Each sessionconsists of one or more ping pong message exchanges. A ping pong message exchange is made up of two packets(a ping and a pong). First, the client sends a packet to the server (the ping packet). The server should interpretthe payload of the ping packet, construct a pong packet, and sends it back to the client. A message exchange isconsidered completed once the client receives the pong packet. Packets are sent using TCP sockets. Multiple pingpong messages may be exchanged serially during a ping pong session (i.e. the second message starts immediatelyafter the first one is completed, and the third message immediately follows the second, and so on).You are recommended to work in a group, each up to three members. You are expected to submit two items:a project report and the source code of your implementation. In your project report, you should also explain yourimplementation and any difficulties you encountered. Please turn in your report and source code (one for eachgroup) in a .tgz file. Please see Section 5 for submission details.2 Part 1 ClientIn part 1, you are asked to implement a client that is able to communicate with the server. There is a serveravailable for class use at copper.cs.ucla.edu (131.179.196.152) using port 4545. For part 1, you do not need to beconcerned with the details of the server implementation.2.1 Running the ClientThe command-line interface to your client must be:./client hserver addressi hserver porti hversioni [ hcounti hpong packet sizei hfilling characteri ]where hserver addressi is the hostname or IP address of the server (copper.cs.ucla.edu or 131.179.196.152), andhserver porti, an integer, is the port number used by the server (4545).The rest of the parameters are used to initiate ping pong exchanges. Each field is separated by a single space:• Version: The version number, should be 1 in this part• Count: This field is an integer specifying the number of ping pong exchanges between the server and theclient.• Pong Packet Size: The size of the payload for each pong packet (in bytes).• Filling Character: A single character which will be used to fill the payload of pong packets.1The client should verify that the user input is valid. For example, both hcounti and hpong packet sizei mustbe integers, and hfilling characteri must be a single character. Once the verification is done, the client should starta ping pong message exchange with the server. Once the message exchange is done, the client must start anotherexchange if the user inputs multiple sets of “hcounti hpong packet sizei hfilling characteri”. See Section 2.3 forexamples.2.2 Ping Pong Message Exchange - Client SideEach ping packet from the client should be sent through a TCP socket using send(). The pong packet is receivedthrough recv(). The client should keep track of how many messages have been exchanged. For each pong packetreceived, you should print its payload to the screen, followed by a newline.2.2.1 Packet PayloadThe payload of ping packet is binary data described by the C structure shown below:struct ping{char version;char fill;unsigned int seq;unsigned int size;};• version: A single character whose value should be ‘\1’ (the number one, not ‘1’ the character).• fill: This is a character, specified as the hfilling characteri mentioned in Section 2.1. For example, if size isset to 4 and fill is set to ‘a’, then you should expect the payload of the pong packet to be “aaaa”.• seq: This is the sequence number of this ping packet starting at 0. It is increased by 1 for each successfulping pong message exchange. So the first ping packet in a session carries a seq of 0, the second ping carriesa seq of 1, and so on.• size: The size of the pong packet payload in bytes, as specified by the hpong packet sizei described inSection 2.1.2.3 Client ExampleBelow is an example of the output from the ping pong client. The portions typed by the user are in gray.% ./client copper.cs.ucla.edu 4545 1 4 10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa% ./client copper.cs.ucla.edu 4545 1 3 2 a 2 6 !aaaaaa!!!!!!!!!!!!3 The ServerOnce part 1 is completed successfully, it is time to write your own implementation of the server.23.1 Running the ServerTo start the server, the user should type:./server hserver portion the command line, where hserver porti, an integer, is the port number that the server will listen on.The server should enter a loop waiting for incoming ping packets. For each ping packet it receives, theserver should read the payload and construct a pong response using the extracted information, as described inSection 2.2.1. That is, it should construct a packet of size size containing only the fill character.3.2 Variable Filling CharacterNow, let’s create version 2 of the ping pong protocol. If the ping request version number is ‘\2’ (when the userinputs 2 for the version number) , instead of constructing the payload of a pong response by using just the fillingcharacter specified in the ping packet, take the sequence number into account as well. Note that any charactercan also be treated as an integer in C. For this part, we compute the filling character using the following equation:filling character in pong response = ((ping filling character + ping sequence number - 33) mod 94) + 33This formula may look arbitrary, but it ensures that all ASCII characters will be visible ones (between codes33 and 126), and that the sequence will start with the requested filling character. For example, the ASCII valuefor ‘a’ is 97. If the filling character from the ping is ‘a’, the filling character used for the first pong packet is (97+ 0 - 33) mod 94 + 33 = 97 (‘a’, as expected), the filling character for the second pong packet is (97 + 1 - 33)mod 94 + 33 = 98 (the ASCII value for ‘b’), and so on. If there were a 30th pong packet in this session, it wouldbe (97 + 30 - 33) mod 94 + 33 = 33, wrapping around to the first visible


View Full Document

UCLA COMSCI 118 - proj1

Download proj1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view proj1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view proj1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?