CS 56   Advanced Java Programming

Week 9

Agenda

References

The Java Tutorial - Custom Networking
Introduction to Java Programming: Week 12, Network Programming by elharo
Thinking in Java, Bruce Eckel, Chapter 15: Network programming

Examples

The following are networking applications.  Download; compile; run (must be online).
Http.java - retrieves a web page from a web server
Page.java - displays my homepage on System.out
WhoAmI.java - displays your IP address; see source code for usage
The following pair of networking applications are run as follows:
  1. download each source file
  2. compile each source file
  3. if not online, go online.  i.e., connect to an ISP (if in lab, you're always online)
  4. enter java JabberServer
  5. open a second command prompt window and go to the folder where the files are
  6. enter java JabberClient
  7. watch the action
JabberServer.java - very simple server that just echoes whatever the client sends
JabberClient.java - very simple client that just sends lines to the server and reads lines that the server sends

Pictures

IP and UDP
TCP
ClientServer
Servlet

Lab21

Do at least two of the following modifications to the JabberServer JabberClient app:
  1. Enhance the JabberServer by adding the ability to handle more than one connection at a time. Use multithreading. When a connection is accepted, create a "worker" thread and pass it the socket. The worker thread then handles further communication with the client.
  2. Enhance JabberServer so that instead of printing the data received from the client to System.out, it displays it in a GUI.
  3. Enhance the JabberClient by adding the ability to get text from the user and then send it to the server. Use a GUI with an area where the user can input the text. You may want to add a send button or perhaps the enter key will suffice.
  4. Change the JabberServer so that instead of echoing back the text received from the client, it gets input from the (server) user and sends that to the client. Notice that this functionality is described in the previous item, but here you are adding it to the server.
Note that if you make all four changes you should now have a chat app. If you plan to do all of the enhancements, you will probably want to "architect" it first. Note that there is some functionality that is common to both the client and server. Factor that out and put it in a separate class. Should be fun.
 
 < CS 56 > Home Email Last Modified October 26, 2001