Anda di halaman 1dari 2

National University

Of Co mputer & Emerg ing Sciences-Isla ma ba d

Computer Networks
Spring 2014 Lab Assignment-1 Deadline: 13th March 2014 At 11:30 PM

Q1. Write a pair of TCP echo client/server program. Server runs at a fix IP address and port
number. The client takes following entities as command line arguments Server IP address Server port number Message length (max 2048) Number of repetitions (No of times messages will be exchanged).

Your client should connect to the server on the given port, record the start time (using standard C++ time library function). Then for the specified number of repetitions, send (write ()) and receive (read ()) an arbitrary message of the specified length. Record the ending time. Use the start and end times to calculate the data rate over the network. Your client program should then print the hostname, repetitions, message length, elapsed time, and kilobits/second. Provide the output from your program in a .txt file when testing with the echo server using 1000 repetitions and message sizes (bytes) of 8, 256, 1024, and 2000. Check error status on ALL network function calls.

Q2. For this problem you have to construct a concurrent TCP knock-knock server using fork() and a TCP knock-knock client . A "knock-knock protocol" goes something like this:
Server: Client: Server: Client: Server: "Knock knock" "Who's there?" "Wendy" "Wendy who?" "Wendy wind blows de cradle will rock"

A knock-knock server waits for a connection, to which it replies with the string Knock knock. It waits for the client to respond with Who's there?, to which it responds with some first-part, usually a name. It waits for the client to respond with first-part who?, to which it responds with a last-part, which involves some semi-humorous word-play on first-part.

To satisfy its side of the "knock-knock protocol", a knock-knock client begins by connecting to the server, and then waiting for the server to send it the string Knock knock. It then displays that string, displays and replies with Who's there?, waits for and displays the server's response, displays and replies with the server's response followed by who?, and lastly gets and displays the server's final response. Some examples of Knock-knock jokes are given below you have to use them in your program, you can also add more examples e.g.

First part
Boo Cows go Doris Dwayne Police

Last Part
Don't cry, it's only a joke No, cows go 'moo', owls go 'who'! Doris locked, that's why I had to knock! Dwayne the bathtub, I'm drowning! Police open the doorits cold out here!

The knock-knock server should use a port of 0 in the bind() so the kernel can assign a port to your server. Use getsockname() to find out what port number has been assigned, and then print out "Server starting on port NNNN so your client will know what port number to use for connecting. Server will be running on a fix IP address. Your main server should spawn a child server after the accept () to serve each client. You need to use signal/waitpid to manage terminated child server. Your child server will randomly select one of the first part-last part pairs from the knock-knock data base. The child server will send the "Knock. Knock." to the client and manage the knock-knock protocol in a manner described above. Be sure the child server terminates when the client aborts/closes the connection by sending an Exit message. Use rand() to randomly select a first part-last part pair. Hint: if you have N pairs, 0 to N-1, then rand ()%N returns a random integer in the range 0 to N-1

SUBMISSION INSTRUCTIONS Submit your codes on SLATE. You are required to submit ONLY a single .txt file having all the code in it No file other than the .txt file will be considered. Name your text file as Section_RollNumber_Assignment1 Plagiarism will be heavily penalized. Submission through SLATE messages or Email will not be accepted.

Anda mungkin juga menyukai