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
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.
- 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:
- Do not specify port for server. Let the system choose a port for you.
Server connected to port 3405!
- Specify server name and port as argument in command line of client.
i.e. client shana3.jct.ac.il 3405
- Server should be able to accept a new client while the previous client
is still communicating (maximum of 3 clients simultaneously !!).
- client should be able to send several lines of text.
- Use fgets() to read line.
- Handle the signal control-c in server and client. First close sockets and then exit program.
- If client sends string quit or disconnects, server should disconnect from him.
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:
- Print the port on which it is listening.
- Send date to client (use function gmtime).
- Send file index.html to client. You will have to write such an html file in the directory where you run the server.
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
Make a small protocol using udp transmission to copy files from the "server" to the "client" computer.
- 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
- The first two bytes of the 18 byte "packet" will contain the
of the packet so that the server can assemble them in order.
- 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.)
- 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.
- Client will only read files from the server.
- 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.
- 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.
- Write a modified version of your client to test the error handling.
- You can choose how the client's acknowledge
packet will be made up.
- Print out the entire packet (including all headers) on each receive.
- 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.
- 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.
- Nothing the client does should cause the server to stop running.
- Use fork() to handle up to 3 clients at once.