Skip to content
Snippets Groups Projects
Commit 9267ca98 authored by brutzman's avatar brutzman
Browse files

Merge origin/master

parents 3593f647 ff5351ba
No related branches found
No related tags found
No related merge requests found
Showing
with 16 additions and 35 deletions
No preview for this file type
......@@ -11,9 +11,6 @@ import java.net.*;
*/
public class SchuttClient {
// IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
public static void main(String[] args) {
// Local vars/fields
......@@ -58,8 +55,7 @@ public class SchuttClient {
System.out.println("==================================================");
System.out.println("Now we're talking!");
System.out.println("The message the server sent was: '" + serverMessage + "'");
// socket gets closed, either automatically/silently by this code (or possibly by the server)
//Send equation to the server and wait for the server's reply
ps.println(eq);
serverMessage = br.readLine();
System.out.println(serverMessage);
......@@ -74,10 +70,7 @@ public class SchuttClient {
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
} finally {
// program exit: tell somebody about that
}
}
}
}
assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttClient.png

291 KiB

assignments/src/MV3500Cohort2019JulySeptember/homework2/Schutt/SchuttServer.png

316 KiB

......@@ -4,20 +4,8 @@ import java.io.IOException;
import java.net.*;
/**
* Very slightly more complex than example1, further modifying example2. The
* only thing this does differently is introduce a loop into the response, so
* you don't have to restart the program after one response. Also, it prints out
* the socket pair the server sees. Run the program via telnet several times and
* compare the socket pairs.
*
* telnet (nc) localhost 2317
*
* If you're sophisticated you can contact the instructor's computer while
* running this program.
*
* telnet (nc) [ipNumberOfServerLaptop] 2317
*
* and have the instructor display the socket pairs received.
* This is a basic Server Dispatcher that awaits a client to connect and then
* hands the client over to a thread handler to do the required work.
*
* @author Schutt
*/
......
......@@ -5,10 +5,8 @@ import java.net.*;
/**
* A program that handles all logic associated with one socket connection by
* running in a thread of its own. This is the server portion as well, so we
* artificially invent what happens if the server can't respond to a connection
* for several seconds. Warning: do not run this class! It is created
* automatically by TcpExample4DispatchServer.
* running in a thread of its own. This thread will calculate a basic preformed
* equation sent by the client.
*
* @author Schutt
*/
......@@ -33,9 +31,10 @@ public class SchuttThreadHandler extends Thread {
}
/**
* Handles one connection. We add an artificial slowness to handling the
* connection with a sleep(). This means the client won't see a server
* connection response for ten seconds (default).
* Handles one connection. We confirm that the connection is made by asking
* the client a basic question and receive a basic equation back from the
* client. The equation is interpreted and solved, with the answer being returned
* to the client.
*/
// @overriding run() method in Java Thread class is deliberate
@Override
......@@ -52,19 +51,20 @@ public class SchuttThreadHandler extends Thread {
ps.println("Please send your equation!");
String clientInput = br.readLine();
String[] parsedInputs = clientInput.split("");
System.out.println("The Client's equation is: " + clientInput);
if(clientInput.contains("+")){
num1 = (int)clientInput.charAt(0);
num2 = (int)clientInput.charAt(4);
num1 = Integer.parseInt(parsedInputs[0]);
num2 = Integer.parseInt(parsedInputs[4]);
System.out.println(num1 + " " + num2);
output = num1 + num2;
}
if(clientInput.contains("*")){
num1 = (int)clientInput.charAt(0);
num2 = (int)clientInput.charAt(4);
num1 = Integer.parseInt(parsedInputs[0]);
num2 = Integer.parseInt(parsedInputs[4]);
output = num1 * num2;
}
......
File added
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