Skip to content
Snippets Groups Projects
Commit bd4e7cda authored by coltonfetterolf's avatar coltonfetterolf
Browse files

No commit message

No commit message
parent 4c5d3a4b
No related branches found
No related tags found
No related merge requests found
......@@ -16,8 +16,7 @@ import java.net.*;
*/
public class FetterolfHomework2Client {
// 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 = "0:0:0:0:0:0:0:1";
public static void main(String[] args) {
......@@ -27,12 +26,10 @@ public class FetterolfHomework2Client {
InputStreamReader isr;
BufferedReader br;
String serverMessage;
OutputStream os;
try {
while (true) {
System.out.println("Creating socket connection...");
System.out.println("Homework 2 is creating socket...");
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
......@@ -45,16 +42,14 @@ public class FetterolfHomework2Client {
is = socket.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
// Read a single line written by the server. We'd
// do things a bit differently if there were many lines to be read
// from the server instead of one only.
serverMessage = br.readLine();
System.out.println("==================================================");
System.out.println("My name is the client!");
System.out.println(serverMessage);
//continue;
System.out.println("Sweet, looked like we're connected!");
System.out.println("The message the server sent was: '" + serverMessage + "'");
// socket gets closed, either automatically/silently by this code (or possibly by the server)
} // end while(true)
......
......@@ -36,10 +36,6 @@ public class FetterolfHomework2Server {
ServerSocket serverSocket = new ServerSocket(2317);
OutputStream os;
PrintStream ps;
InputStream is;
InputStreamReader isr;
BufferedReader br;
String clientResponse;
InetAddress localAddress, remoteAddress;
int localPort, remotePort;
......@@ -53,13 +49,9 @@ public class FetterolfHomework2Server {
// Now hook everything up (i.e. set up the streams), Java style:
os = clientConnection.getOutputStream();
is = clientConnection.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
ps = new PrintStream(os);
ps.println("The server says 'Yo, what up?'"); // this gets sent back to client!
ps.println("Yo what up. "); // this gets sent back to client!
clientResponse = br.readLine();
// Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair).
localAddress = clientConnection.getLocalAddress();
......@@ -72,10 +64,9 @@ public class FetterolfHomework2Server {
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
// Why is the first IP/port the same, while the second set has different ports?
System.out.println("TheServer socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( "
System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( "
+ remoteAddress.toString() + ", " + remotePort + " ))");
//Prints message from client
System.out.println(clientResponse);
// 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