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

improved logging format

parent 23d8f515
No related branches found
No related tags found
No related merge requests found
Program response:
Invocation instructions:
* run/debug TcpExample1Telnet.java
* console: telnet localhost 2317
Program responses:
===================================================
run:
TcpExample1Telnet has started and is waiting for a connection: telnet localhost 2317
This server response was written by server TcpExample1
......@@ -7,6 +12,7 @@ BUILD SUCCESSFUL (total time: 13 seconds)
Telnet window:
===================================================
don@it154928 /cygdrive/c/Program Files/NetBeans 8.2
$ telnet localhost 2317
Trying ::1...
......
......@@ -10,14 +10,14 @@ import java.net.*;
* out the socket pair the server sees. Run the program via telnet
* several times and compare the socket pairs.
*
* telnet localhost 2317
* <code>telnet localhost 2317</code>
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* <code>telnet ipOfServersLaptop 2317</code>
*
* And have him display the socket pairs he got.
* And have that machine display the socket pairs received.
* @author mcgredo
*/
public class TcpExample2ConnectionCounting
......@@ -33,7 +33,7 @@ public class TcpExample2ConnectionCounting
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
int connectionCount = 0; // state
int connectionCount = 0; // state variable
ServerSocket serverSocket = new ServerSocket(2317); // server decides here what port to listen on.
// of interest: often client doesn't care what port it uses locally when connecting to that server port.
......@@ -49,8 +49,8 @@ public class TcpExample2ConnectionCounting
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server TcpExample2"); // to remote client
System.out.println("This server response was written by server TcpExample2"); // to server console
ps.println("This client response was written by server TcpExample2ConnectionCounting"); // to remote client
System.out.println("This server response was written by server TcpExample2ConnectionCounting"); // to server console
ps.println("You were connection #" + connectionCount + ", by my count");
......
Invocation instructions:
* run/debug TcpExample2.java
* console: telnet localhost 2317
Program responses:
===================================================
run:
TcpExample2ConnectionCounting has started and is waiting for a connection: telnet localhost 2317
This server response was written by server TcpExample2ConnectionCounting
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 57630 ))
got another connection, #1
This server response was written by server TcpExample2ConnectionCounting
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 57631 ))
got another connection, #2
This server response was written by server TcpExample2ConnectionCounting
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 57633 ))
got another connection, #3
===================================================
don@it154928 /cygdrive/c/Program Files/NetBeans 8.2
$ telnet localhost 2317
Trying ::1...
......
......@@ -53,7 +53,7 @@ public class TcpExample3Server {
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
......
Invocation instructions:
* run/debug TcpExample3Server.java
* run/debug TcpExample3Client.java
Program responses:
===================================================
run:
TcpExample3Server has started...
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49239 ))
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49240 ))
Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49241 ))
[etc.]
[kill process to exit]
===================================================
run:
TcpExample3Client creating socket...
==================================================
......
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