TCP/IP Lab Homework: Ellul 5767 (2007)

These homework assignments.

note: To compile sockets on commandline in solaris, write something like this: cc -o mySocket -lsocket -lnsl mysocket.c
  1. Copy my simple_sender and simple_receiver but add to them the feature that you can write several messages to the server and he will print them all. The client is to be ended simply by ctrl-c. There server will not exit when client ends, but will be ready to handle new clients.
  2. Write two programs (one server one client) using unix tcp sockets to allow characters typed on one computer to be sent to another computer. Use tcp connection oriented communication. For a very detailed tutorial on sockets try Beej's Guide and if you want a Hebrew translation try here.
    Points of clarification for this and the 2nd exercise:
  3. Write a very simple http server using TCP functions. The server will listen on a free port, not 80. You will therefore need to specify in the url the port number preceded by a colon. The server needs to do the following things: You do not need to check all the headers that the browser will send you. Simply check for this:
    Optional: If the browser specifies a file name like this "http://loccalhost/file.html" the server will send that file and not index.html.
    For information on the http headers see explanation of http protocol
  4. Make a small protocol using udp transmission to copy files from the "server" to the "client" computer.
    1. Write a udp server with the limitation that the sending and receiving buffer is only 18 bytes long. Only the last 13 bytes of which can be used to put the string or file in, therefore a string or file will be sent sometimes in many send calls.
    2. The first two bytes of the 18 byte "packet" will contain the number of the packet so that the server can assemble them in order.
    3. The 3rd 4th and 5th bytes will be a special ID number assigned by the server to make sure he is still talking to the same client. (Use all possible binary values for number, i.e. maximum number is not 999, but is 2 to the 24th power.)
    4. On the first connection, the client will send 0 as the packet number and the remaining 17 bytes of the packet will be used for the file name followed by \0. Since this is the first packet, there will be no special ID number.
    5. Client will only read files from the server.
    6. After each data packet from the server, the client will send an acknowledgement that he received the packet (for example packet number 1, or 2 or 3 etc.) and the server will check this packet number and know to then send the next packet in order.
    7. Check that packets do not arrive out of order. If the client sends a wrong packet number, the server will resend the last data packet he sent.
    8. Write a modified version of your client to test the error handling.
    9. You can choose how the client's acknowledge packet will be made up.
    10. Print out the entire packet (including all headers) on each receive.
    11. Use the open and write commands in UNIX to write the data of each packet to the file of the name given by the 0th packet.
    12. The end of a file is indicated to the server when he receives a packet whose size is less than 18. After receiving such a packet, the client should send an acknowledge and exit. The server should receive the acknowledge and return to a state where he waits for a new file to be requested.
    13. Nothing the client does should cause the server to stop running.
    14. Use fork() to handle up to 3 clients at once.