Program 1


Download the Client and Server programs and compile them. You shouldn't get any errors unless you are working on a non-BSD type Unix.

These programs use the Internet protocol mechanisms to communicate, but for now, you will limit yourself to running the programs on the same machine.

The first thing you should do is make sure that the machine address in the client program is correct for your machine. In the example, the address is 153.90.192.1, but the correct internet address for your machine can be found in the file /etc/hosts. It is the address specified along with the name of your host.. Also, you may want to choose a port number other than 32351. You can choose any value between 1024 and 65535, but something larger than 8000 is safest. If you don't choose a different number, you could potentially have a conflict with someone else using the same port, although that should be unlikely.

If you compile your programs with commands of the form:
the application is executed by running the server in the background with something of the form ``server1 &''. Then execute client1. Currently, the communication is all one-way with the client sending messages to the server. Modify it so that it implements two-way communication where the server waits for a message and then sends a response, which the client processes. The communication protocol to implement is the following:
   Client sends a message of the form "Hello, my name is _____" 
   The server responds with "Hi ______, OK" and prints out  
      "Talking to _______" 
   The client sends 2 or more messages which comprise a saying you like, 
      such as "In a battle of wits" 
              "You are an unarmed man"
   The server responds to each message with "Received OK" and prints it out
      in the form "Server received: ...".
   The client finally terminates with "_______ done"
   The server responds with "Done OK"
Each _____ should be replaced with your name and the client should print out every message received from the server in the form "Client received: ...".

In order to turn in the output, use the script command to create a file containing all of the output from the client or server:

   script myrun

Use Control-D or the Exit command to terminate the script when you are done executing the client or server. Turn in the test runs with your code.

In this particular situation, your server should also quit or be killed when the client finishes.

The order of the messages may be mixed, because you have no control over when the processes get a CPU time slice. For example, you might see all the client messages together, even though the client and server processing is interleaved if you set up the protocol correctly.

Whatever you do, DON'T LEAVE YOUR SERVER PROCESSES RUNNING. The example program terminates after a certain number of messages, but that is not typical server behavior. If you wait for the client to initiate the termination, the server could potentially keep running.

If you run a job in the background, it will not be terminated when you log out. Use the ps command to list your processes. If you have any unnecessary processes running, use ``kill -KILL pid'' to get rid of them. pid is the process id that is listed by the ps command under PID. If you fail to do this, you may cause significant problems for yourself or for others. This cannot be emphasized enough, so if you have a hard time remembering this, alias logout to a script that runs ps or reminds you to kill jobs. If you are using bash as your shell, create a file named .bash_logout in your home directory and put the following in there:

   ps

You will be logged out, but you will see any processes running. You can get more fancy than this and kill extraneous processes, but that is up to you. If you are using tcsh, create a file named .logout in your home directory and put a ps command in there.

UNDER NO CIRCUMSTANCES SHOULD YOU BE RUNNING THESE PROGRAMS ON ESUS. Esus is a general purpose server, and if you leave extra processes there, or make a major mistake and cause esus to have to be rebooted, everyone suffers. So, no matter how good you think you are, it is easy to make a mistake with these programs, so use the lab machines in EPS 254 or some other host for all programming for this course.

If you are using X-windows, you can run each process in a different window instead of using background execution.

On the web page follow CS440 -> Laboratories -> Resources -> Unix Network Programming Manual to get some help on this and other assignments.