Skip to content
Snippets Groups Projects
Commit 9af45fe4 authored by pughb's avatar pughb
Browse files

Homework 1: Pugh

parent 0b2fad7d
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ public class Pugh3Client_homework2 {
System.out.println("That is a horrible joke.");
}
if (clientLoopCount == 4){
if (clientLoopCount >= 4){
System.out.println("No...");
}
Thread.sleep(500l); // slow things down, for example 500l (long) = 500 msec
......
......@@ -58,21 +58,8 @@ public class Pugh3Server {
// Now hook everything up (i.e. set up the streams), Java style:
os = clientConnectionSocket.getOutputStream();
ps = new PrintStream(os);
ps.println("This is response " + serverLoopCount + " produced by the server."); // this gets sent back to client!
ps.println("This is response " + serverLoopCount + " produced by the server.\n"); // this gets sent back to client!
if (serverLoopCount == 1) {
System.out.println("Ready for some great Dad Jokes?!?");
}
if (serverLoopCount == 2) {
System.out.println("Ok, get ready...");
}
if (serverLoopCount == 3) {
System.out.print("A ham sandwich walks into a bar and orders a beer. The bartender says, “Sorry, we don’t serve food here.”");
}
if (serverLoopCount == 4) {
System.out.println("Funny, right?");
}
// Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair).
localAddress = clientConnectionSocket.getLocalAddress();
......@@ -80,7 +67,7 @@ public class Pugh3Server {
localPort = clientConnectionSocket.getLocalPort();
remotePort = clientConnectionSocket.getPort();
System.out.print("Server loop " + serverLoopCount + ": ");
System.out.print("Server loop: " + serverLoopCount + "\n");
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
......@@ -90,14 +77,32 @@ public class Pugh3Server {
System.out.println(Pugh3Server.class.getName() + " socket pair showing host name, address, port:");
System.out.println(" (( "
+ localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( "
+ remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
+ remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))\n");
if (localAddress.getHostName().equals(localAddress.getHostAddress())
|| remoteAddress.getHostName().equals(remoteAddress.getHostAddress())) {
System.out.println(" note HostName matches address if host has no DNS name");
System.out.println(" note HostName matches address if host has no DNS name\n");
}
}
if (serverLoopCount == 1) {
System.out.println("Ready for some great Dad Jokes?!?\n");
}
if (serverLoopCount == 2) {
System.out.println("Ok, get ready...\n");
}
if (serverLoopCount == 3) {
System.out.print("A ham sandwich walks into a bar and orders a beer. The bartender says, Sorry, we don’t serve food here.\n");
}
if (serverLoopCount == 4) {
System.out.println("Funny, right?\n");
}
if (serverLoopCount >= 5) {
System.out.print("Keep laughing, it's funny!\n");
}
// Notice the use of flush() and try w/ resources. Without
// the try w/ resources the Socket object may stay open for
// a while after the client has stopped needing this
......
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