Assignment 2
Week beginning November 26th 2001
Mr. John Mc Donald
Objective: The objective of this practical is to introduce the student to the use of sockets in writing a client for the hangserver program written in the previous assignment.
Procedure:
Download and compile the client code:
Step 1. Read through the handout given to you. If you do not understand any part of it you should ask the demonstrator
Step 2. Download hangclient.c program and the words file from
www.cs.may.ie/~johnmcd/cs320/labs/hangman/hangclient.c
Step 2a. Place the file in your networkslab directory and compile it using
/usr/local/bin/gcc –o hangclient hangclient.c –lsocket –lnsl
You need both libraries specified so that the linker can resolve all external references used
Step 3. Step through each line of code in the client and try and understand what each one does
Use the client to connect to the server on the localhost:
Step 4. Open a terminal window on your machine
Step 5. Run the hangman server
Step 6. Run netstat to verify that your server is running and listening on port 1066
Step 7. Open another terminal window and run the hangclient program passing no arguments. This will make it connect to the localhost by default.
Step 8. Document what happens (i.e. on the screen, and in terms of network sockets)
Use the client to connect to the server on your neighbour’s machine:
Step 9. Find out your neighbour’s machine name. Use hangclient to connect to your neighbour’s machine as follows
hangclient neighbours_machine_name
For example: hangclient l2sol23
Step 10. Get you neighbour to monitor the connection using netstat –a
Step 11. Using comments explain your understanding of each line of code.
Extend the functionality of the server and client:
Step 12. Alter the client code so that it accepts the name of the player as a second argument and immediately after the connect statement sends it to the server
Step 13. Alter the server code so that once a connection is accepted it reads the name of the player and prints it to the screen