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. Instead of the server writing contents of a file to the socket, it will execute a one word command and send the results to the socket. The client will still read from the socket, but before it does, it will write to the socket a command that you want to execute on the server. This command will come from the user and must be a one word command such as: last, who, pwd, ls.

Once a connection is established, your client will:

Once a connection is established your server will:

Common Error!

You can run into trouble in your client if you do not send the command 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).


Submit 2 files to URCourse

The test runs will be performed in the lab