20-CS-694 Advanced Programming Techniques Spring 2012
Internet

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

All lectures
TCP, UDP, HTTP -- Servers and Clients

This series shows how to use many of the classes associated with internet connection handling. Click on the class names in the following table to see class details.

DatagramPacket DatagramSocket InetAddres ServerSocket Socket
URL URLConnection Serializable MalformedURLException

1.   WebServe.java

  -   Operate a simple Web server. This one has no security and does not always handle content correctly, but it is muti-threaded so a new connection is spawned whenever a new client requests a file.

Click on 'Start Server' and in a brower location field type

  http://localhost:8080/<name-of-some-file-in-your-home-directory>
You can download apache_p.gif and index.html if you wish.
Documentation.
 
2.   ClientServer.java
ServerApplet.java
ClientApplet.java

  -   This example shows that a server can be connected to numerous clients on the same port without any one connection interfering with any other. A single server window and two client windows appear. Start the server by clicking the 'Start Server' button. Pick a client and click its 'Connect' button. The 'Ready to send' message appears at the top of the applet. Type a message into the JTextField below the 'Input' label and click the 'Send It' button. The server will show the message that it received, who it was received from, and send it back to the proper client.

Up to 100 clients can be connected to this server at a time. All the server does is echo text that is directed to the server from the clients.

 
3.   ProxyServer.java
ProxyClient.java
server

  -   The compiled ProxyServer class resides in <httpd-root>/cgi-bin of gauss.ececs.uc.edu. It is started by means of shell script named server which is also in <httpd-root>/cgi-bin of gauss.ececs.uc.edu. The contents of server are:
  #!/bin/sh
  /usr/local/java/bin/java ProxyServer $1
The script is invoked from a browser with, for example, the following URL:
  http://gauss.ececs.uc.edu/cgi-bin/server?yahoo.com

The ProxyClient applet which is run from the 'Applet' button on the left is a client that uses the ProxyServer on gauss directly. To put the proxy server on your computer, download and compile ProxyServer.java and place ProxyServer.class in <httpd-root>/cgi-bin or whatever your webserver's cgi root is (check the webserver's config file). Also download the script server and place it in the cgi root directory, making it executable. Start your http server (usually apache). A sample query is:

  gauss.ececs.uc.edu/franco_files/index.html
Click on the 'Get It!' button to make the query - only text is displayed.
 
4.   RProxyServer.java

  -   This is a proxy server for typical web browsers. Your browser's network settings need to be configured to use it. In the case of Firefox, select the 'Edit' menu and click on 'preferences'. Click on the 'Advanced' tab then the 'Network' tab. Click on connection 'Settings'. Click on 'Manual Proxy Configuration' and under 'HTTP Proxy' enter 'localhost' and '8690' for the 'Port'. Click on OK to save the configuration. The browser then points to the proxy server, if it is running. To run it, hit 'Start Server'. This is intended for demonstration purposes only and cannot serve all files correctly.
 
5.   NewProxy.java
NewProxyServer.java
NewProxyClient.java

  -   This is another proxy server. This one one is different from the one above in that it does not use CGI. Click the 'Start Server' button to begin. Enter a query in the client, for example yahoo.com and click the 'Get It!' button. The transaction at the server is shown in the server window, and what the client puts to the server and gets from it is shown in the client window. Only text is handled properly.
 
6.   DatagramApplet.java
DatagramServer.java
DatagramClient.java

  -   This example shows how a client assembles a datagram packet, sends it to a server, and how the server sends a response to a client. Any datagram packet received by the server is considered a request for the current date and time. The response is encoded as a human readable ascii string, inserted into a packet and sent to the initiator.

Start the server by clicking the 'Start Server' button. Get a date by clicking the 'Get Next Date' button in the client.

 
7.   RV.java
RVServer.java
RVClient.java

  -   An 'Application' object is sent by the client process to the server. A pipeline is connected to the application and then the application is executed. The output from the application is viewed, via the pipeline, in a JTextArea on the server. The application object is threaded and can be immediately started when it arrives at the server. The application object extends PipedWriter to allow a simple connection to be made between it and the server.
 
8.   RV.java
RVServer.java
RVClient.java

  -   This is similar to the above. An executable object is run for a time in the client, then suspended, then teleported to the server, and run some more. The executable object is a Stream network consisting of the Merge of two Times Streams multiplying Successor Streams by 3 and 5.