Skip to content
Snippets Groups Projects
Commit 594f76bc authored by brutzman's avatar brutzman
Browse files

update example and terminal log

parent b555debc
No related branches found
No related tags found
No related merge requests found
......@@ -30,19 +30,20 @@ import java.net.*;
public class TcpExample1Telnet
{
@SuppressWarnings("ConvertToTryWithResources")
public static void main(String[] args)
{
try
{
System.out.println("TcpExample1Telnet has started and is waiting for a connection: telnet localhost 2317" );
System.out.println("TcpExample1Telnet has started and is waiting for a connection:");
System.out.println("Enter (telnet localhost 2317) or (nc localhost 2317)..." );
// The ServerSocket waits for a connection from a client.
// It returns a Socket object when the connection occurs.
ServerSocket serverSocket = new ServerSocket(2317);
// The Socket object represents the connection between
// the server and client, including a full duplex
// connection
// the server and client, including a full duplex connection
Socket clientConnection = serverSocket.accept();
// Use Java io classes to write text (as opposed to
......@@ -50,16 +51,17 @@ public class TcpExample1Telnet
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server TcpExample1"); // to remote client
System.out.println("This server response was written by server TcpExample1"); // to server console
ps.println("This client response was written by server TcpExample1."); // to remote clientnc
System.out.println("This server response was written by server TcpExample1."); // to server console
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
ps.flush();
clientConnection.close();
System.out.println("TcpExample1 completed successfully.");
}
catch(Exception e)
catch(IOException e)
{
System.out.println("problem with networking: " + e);
}
......
Invocation instructions:
1. run/debug TcpExample1Telnet.java
2. console: telnet localhost 2317
2. console: nc localhost 2317
alternate: telnet localhost 2217
Program responses:
===================================================
run:
TcpExample1Telnet has started and is waiting for a connection: telnet localhost 2317
This server response was written by server TcpExample1
BUILD SUCCESSFUL (total time: 13 seconds)
TcpExample1Telnet has started and is waiting for a connection:
Enter (telnet localhost 2317) or (nc localhost 2317)...
This server response was written by server TcpExample1.
TcpExample1 completed successfully.
BUILD SUCCESSFUL (total time: 5 seconds)
Telnet window:
===================================================
netcat window:
brutzman@DESKTOP-2S09UKA /cygdrive/c/Program Files/NetBeans_11.0/bin
$ nc localhost 2317
This client response was written by server TcpExample1.
===================================================
Telnet window:
don@it154928 /cygdrive/c/Program Files/NetBeans 8.2
$ telnet localhost 2317
Trying ::1...
Connected to localhost.
Escape character is '^]'.
This client response was written by server TcpExample1
This client response was written by server TcpExample1.
Connection closed by foreign host.
===================================================
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