Skip to content
Snippets Groups Projects
Commit b4cfc9e5 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

improved diagnostics, comments

parent 955ed8bc
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ import java.io.*;
import java.net.*;
/**
* Before, we always used telnet to connect to the server. We
* are now writing our own program to do the connection.
* Before, we always used telnet to connect to the server.
* Here we are now writing our own program to do the connection.
*
* As you will see, when we run this after we start the server
* we will see the same string telnet printed, sent by the server.
......@@ -17,11 +17,14 @@ import java.net.*;
*/
public class TcpClient {
public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1
public static void main(String[] args)
{
try
{
while(true)
{
System.out.println("creating socket");
// We request an IP to connect to ("localhost") and
......@@ -29,7 +32,7 @@ public class TcpClient {
// a connection to that IP in the form of the Socket
// object; the server uses a ServerSocket to wait for
// connections.
Socket socket = new Socket("localhost", 2317);
Socket socket = new Socket(LOCALHOST, 2317); // locohost?
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
......@@ -39,15 +42,19 @@ public class TcpClient {
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("==================================================");
System.out.println("Now we're talking!");
System.out.println("The message the server sent was " + serverMessage);
// socket gets closed, either automatically/silently this code (or possibly by server)
} // end while(true)
}
catch(Exception e)
catch(IOException e)
{
System.out.println("Problem with client: "); // describe what is happening
System.out.println(e);
System.out.println("Problem with client");
}
// program exit: tell somebody about that
System.out.println("client exit");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment