Activity 9.6 - Putting the simple client and server together

Topic

In this activity we try out the simple server discussed in section 7.1 of Unit 9, using the client code discussed in section 7.2. This is similar to Activity 9.5 except that we are using our own client code instead of the telnet client.

Materials

For this activity there are two separate projects, Ex9_6Server and Ex9_6Client. The instructions for this activity and the Solution document can be accessed from both projects.

You should start from the server project if you have not already done this.

In addition to the Solution document, the server project for this activity contains two classes, which are complete:

In addition to the Solution document, the client project also contains two classes, which are complete:

Important - before you start

In this and the activities that follow you must ensure that no server processes are still running from a previous activity. Otherwise two server processes may compete for the same port, causing an exception.

Open the NetBeans Runtime window and expand the Processes node. Right-click on any running processes, then select Terminate Process.

Task

To run a server program and then a client program on the same machine, and to observe the communication between these two programs.

Instructions

  1. Open the project Ex9_6Server and run it, to start up the server. You should get a message indicating that the server is starting up. The server is set to listen on port 3000.

    Note that if you have a firewall running you may be asked if you want to allow javaw.exe to act as a server.

  2. Open the project Ex9_6Client, set it as the main project and run it. For this activity you do not need to be connected to the internet, since both the client and the server are running on the same computer. In this case, the client does not have a user interface as all it does is connect to the server, receive and display a message, and then terminate.

    You should see a reply from the server. The connection between the client and the server should then be closed and both programs will terminate.

  3. If you want to try again, you have to run the server project again to restart the server and then run the client project again, as before.