Skip to content
Snippets Groups Projects
Commit a86d218f authored by Peter's avatar Peter
Browse files

Pending documentation

parent 8a40c326
No related branches found
No related tags found
No related merge requests found
......@@ -25,22 +25,30 @@ public class SeversonAssignment1 {
try {
//Instantiate socket and wait for connection
ServerSocket serverSocket = new ServerSocket(2317);
//Count the number of connections
int connection = 0;
//Loop until client connection is made
while (true) {
//Socket making connection with the client
Socket clientConnection = serverSocket.accept();
//number of connections is incremented by one when the connection occurs
connection++;
//write output text to the client and server
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
//connection responses to the server and client
ps.println("This client response was written by server"); // to remote client
System.out.println("This server response was written by server"); // to server console
ps.println("Got another connection! " + "--Number " + connection);
//Print port and IP addresses of the server connection
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
......@@ -49,6 +57,7 @@ public class SeversonAssignment1 {
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))");
//close the connection and inform the client of the close
ps.println("The client connection is closed ---- BYE!");
ps.flush();
clientConnection.close();
......
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