Lab Assignment--Sockets


Create two-way communication so that the client and server both read and write to the socket.


The sample code from the lab has the server writing the contents of a file to the socket. The client, by reading the socket, is then able to display the contents of the file to the user. You would now like to specify on the client side what file you actually want to read on the server.

Once a connection is established, your client will:

Once a connection is established your server will:

Common Errors!

Error #1

You can run into trouble in your client if you do not send the filename with the NULL terminator ('\0') as the last character.

Having said the above, your server should account for the client not properly NULL terminating (not sending '\0' as the last character of) the data. You can do this by loading the array that stores the command with NULL terminators (think "for" loop before reading from the socket), or use a function that does it for you (look up bzero).

Error #2

When you read the filename, you do not want to loop. You just need to read one thing.

Error #3

Remember that on the server side you will work with "sfd" to send information over the socket.

Deliverables (2 code files):

The run will be demonstrated in the lab