Background
In this exercise you will be using some Java programs to illustrate the use of sockets. There are two parts to this problem.
Part 1 - The Task
Networked computers provide a number of services to the outside world through the use of ports. You will use a Java program called portPokerClient that will allow you to see the response from specific ports on a number different computers. A listing of commonly used ports is available here. Descriptions associated with the ports are available here.
For this exercise you will need to compile and execute portPokerClient. Directions on how to compile and execute a Java program are given below.
Once you've successfully compiled the program, you can then execute it with parameters that represent a networked computer and a port. Look at the following interaction (user input in bold):
$ java portPokerClient mathcssun1.emporia.edu 80 <enter a command> GET / Server name: mathcssun1.emporia.edu/198.248.182.6 Server Port: 80 Client Port: 33530 Returned from server: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
$
In the above example, the user contacted mathcs1.emporia.edu, port 80. The user then sent the text string "GET /" to port 80. The response from the server is shown above.
Part 1 - What to Turn In
For this part, investigate these sites and ports.
|
Site |
Port |
Enter this when prompted |
mathcssun.emporia.edu |
80 |
GET / |
mathcssun.emporia.edu |
80 |
stuff |
mathcssun.emporia.edu |
7 |
how can you be in two places at once? |
mathcssun.emporia.edu |
19 |
stuff |
mathcssun.emporia.edu |
99 |
stuff |
mathcssun.emporia.edu |
26713 |
stuff |
mathcssun.emporia.edu |
21 |
stuff |
anon.cs.emporia.edu |
17 |
stuff |
For each site/port combinarion provide:
Part 2 - The Task
For this part you implement both a client and server application. Compile TCPClient.java and TCPServer.java. When you compile these applications, you will notice some error messages. this indicates that the programs as written have errors. You will need to modify the following:
Now start the server as:
$ java TCPServer &
Now start the client as:
$ java TCPClient
Enter some text strings and note the output.
Part 2 - What to Turn In
A screen shot of your interaction with the server.
How to Compile and Execute a Java Program
Find or create a Java program. Java program files have the file extension .java. In our example, we will create and use a file called helloWorld.java. The contents of the file are:
import java.io.*;
class helloWorld {
public static void main(String argv[]) throws Exception
{
System.out.println("Hello World\n");
}
}
First we will compile the program. The compiler takes the helloWorld.java file and translates it into Java bytecode which it places into a file with the same name as the helloWorld.java file but with a new extension of .class so that the new file created is helloWorld.class. The bytecode is what is needed in order to run the program.
To compile, at the $ prompt enter:
javac helloWorld.java
This will comile the program and generate helloWorld.class. To run the program enter:
java helloWorld
This will begin the program's execution.