Skip to content
Snippets Groups Projects
Commit de7daa17 authored by adfis's avatar adfis
Browse files

Fisher Homework 2 - Draft

parent e5b1abcb
No related branches found
No related tags found
No related merge requests found
......@@ -22,8 +22,9 @@ import java.net.Socket;
public class FisherClient {
// IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
public final static String LOCALHOST = "0:0:0:0:0:0:0:1";
public final static String LOCALHOST = "172.20.145.10"; //"0:0:0:0:0:0:0:1";
// if we sub localhost with someone's IP this
//should work the same
/**
* Program invocation, execution starts here
* @param args command-line arguments
......@@ -42,14 +43,14 @@ public class FisherClient {
try {
System.out.println("FisherClient creating socket...");
while (true) {
while (clientLoopCount <= 10) {
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
// a connection to that IP in the form of a Socket
// object; the server uses a ServerSocket to wait for
// connections.
socket = new Socket(LOCALHOST, 2317); // locohost?
socket = new Socket(LOCALHOST, 2317);
os = socket.getOutputStream();
ps = new PrintStream(os);
......@@ -67,6 +68,8 @@ public class FisherClient {
System.out.println("The message the server sent was: '" + serverMessage + "'");
System.out.println("FisherClient responds with: To get to the other side");
System.out.println("Loop count: " + clientLoopCount);
clientLoopCount++;
// socket gets closed, either automatically/silently by this code (or possibly by the server)
} // end while(true)
......
......@@ -51,11 +51,13 @@ public class FisherServer {
InputStream is;
InputStreamReader isr;
BufferedReader br;
int serverLoopCount = 0;
// Server is up and waiting (i.e. "blocked" or paused)
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while (true) {
while (serverLoopCount <= 10) {
// block until connected to a client
try ( Socket clientConnectionSocket = serverSocket.accept()) {
......@@ -96,6 +98,7 @@ public class FisherServer {
// the try w/ resources the Socket object may stay open for
// a while after the client has stopped needing this
// connection. try w/ resources explicitly ends the connection.
serverLoopCount++;
ps.flush();
// like it or not, you're outta here!
}
......
......@@ -47,7 +47,7 @@ public class TcpExample3Client {
// a connection to that IP in the form of a Socket
// object; the server uses a ServerSocket to wait for
// connections.
socket = new Socket(LOCALHOST, 2317); // locohost?
socket = new Socket(LOCALHOST, 2317); // locohost?
// Now hook everything up (i.e. set up the streams), Java style:
is = socket.getInputStream();
......
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