Experiments With Client-Server Programs
CS 3000 -- Lab Assignment #9
Directions
Wait until you have read chapter 28 (Example Of A Client And A
Server) before you do this lab.
Copy Sources
Copy the
client
and
server
source code to a location somewhere in your home directory on a Unix host.
Don't change their names: client.c and server.c.
Compile Sources
Do
cc -o client client.c
and
cc -o server server.c
Now you have executable versions of the client and server
code. Their names are simply "client" and "server."
Test The Client Independently
Use section 28.11 (Using The Example Client With Another
Service) as a guide. Test the client program.
Test The Server Independently
Do
ps -ef
and see if any of your classmates are running the server. If
so, you will have to agree on different port assignments.
Start up the server with this command:
server &
or with this command, if you need to choose a port number
different from the default of 5193:
server xxxx &
(For xxxx, you substitute the port number you chose. The
number should be higher than 1024.)
This should execute the server in the background. (If you get
a "bind failed" error message, it's probably because the port
number you chose is already in use. you need to choose a
different number.)
When you have succeeded in executing the command you will get a
shell prompt back immediately, and now you can test the running
server using telnet:
telnet localhost xxxx
For "localhost" you may substitute the actual name of the host
you are using, but the string "localhost" should work, since
unix networking software uses this as an alias for whatever
system you are on.
(Compare with section 28.12 in the text: Using Another Client To Test
The Server)
Test The Client and Server Together on the Local Host
With the server still running, start up the client like this:
client localhost xxxx
Test The Client And Server On Different Hosts
Do the command
fg
and then do a control-c. This will terminate the exectution of
the server program that has been running on the local host.
Now use telnet or rlogin to do a remote login to one of the
other Sun Ultras that share your home directory. After logging
in remotely, start up the server program on the remote host.
Next run your client again on the local host like this:
client remotehost xxxx
For remotehost substitute the name of the remote host
running the server. For xxxx substitute the port number
on which the server is listening.
When finished, terminate the running server program on the remote host (it
will not terminate automatically when you logout -- please do not
leave it running.)
To Turn In:
There now, wasn't that smashing fun? Next just make some minor alterations
to this simple client-server code: Turn it into the next Internet "killer
app." After you make your first million, e-mail me your second million.
:-)