Virginia Tech

Department of Computer Science

CS4254 Computer Network Architecture and Programming

Spring 2006

 

Homework 4 (Total 50 pts)

Due by Midnight on Wednesday March 15th, 2006

 

This homework will be submitted online using the Curator system at http://courses.cs.vt.edu/curator/CourseLinks.html. Follow the link that has our course name and number. You should have received an email listing your username and password for the submission system. If not, please contact the course TA immediately. Please package your submission into a single folder, with subfolders the different homework questions’ answers. Please do not submit binaries or object files. Your source code should be accompanied by a make file and a README file explaining how to generate relevant binaries, and any other necessary information to run your programs. Every student gets a maximum of 3 submissions. Your last submission will be the one to be graded. No late submission will be accepted.

 

Q1. (5 pts) Write C source code to verify whether the IP address and ephemeral port assigned to a client TCP socket are assigned after calling socket, or after calling connect. What do you conclude?

 

Q2. (5 pts) Using your code in Q1, write C source code to estimate the connection timeout delay in effect on accessible lab machines for a TCP client/server connection. You can use the TCP daytime client/server as a starting point. Hint: set the time before attempting connection in the client. Attempt to connect to a non-existing IP address, then get the time after the connect call returns with a time out error. Try it on several machines report your results. What do you conclude?

 

Q3. (5 pts) Write C source code for a TCP server to test what happens if you passed the backlog value as 0. Will the server accept connections in that case? What can you conclude from this experiment? Attempt to try this experiment on a number of different operating systems.

 

Q4. (5 pts) Write C source code for a TCP server to test what happens if you removed the call to bind, but allowed the call to listen. Comment on your results. What would be the server port in that case? Can you display the server port?

 

Q5. (30 pts) Write TCP client/server programs with the following specifications.

TCP client

  • The client connects to a TCP server. (The server’s IP and port as passed to the client as command line arguments).
  • Upon successful connection, the server sends back to the client the string “START”.
  • Upon receiving “START”, the client displays 4 options for the user.

Ø      Option 1 is “get time of day”

Ø      Option 2 is “get connection history”

Ø      Option 3 is “Echo Mode”

Ø      Option 4 is “Exit the program”.

  • If the user selects option 1, the client sends 1 to the server, which responds with the current time of day.
  • If the user selects option 2, the client sends 2 to the server, which responds with the last 5 connections made to that server. The connection information includes the client’s IP address, port, and sent option.
  • If the user selects option 3, the client and server enter into an echo mode, where the client reads a user-provided string and sends it to the server. The server in turn echoes the string back to the client. This mode terminates when the user enters the special keyword “DONE” as its input.
  • Assume that the client will only get one chance to choose his option and then the program exits after displaying the server’s response(s), or after the echo mode is exited, if the selected option is 3 (The client will initiate active close).

 

TCP server

  • The server is started with its server port as a command line argument.
  • The server responds to client requests by sending the “START” string.
  • Only 3 valid communicated values are expected from the clients: 1, 2, or 3.
  • Any other communicated values should be responded to with a “Service not provided” message.
  • Would you choose to implement a concurrent server?

 

Your code should provide suitable error checking and diagnostic messages. For example, you need to handle the case where you try to bind the server port, and the port is already occupied (bind will return an error).