Skip to content
Snippets Groups Projects
Commit fcb0c58d authored by tjsus's avatar tjsus
Browse files

fixing Assignment 1 & 2 Javadoc

parent c11457bf
No related branches found
No related tags found
No related merge requests found
...@@ -4,14 +4,28 @@ import java.io.*; ...@@ -4,14 +4,28 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.util.Scanner; import java.util.Scanner;
/**
* Client constructor
*/
public class HomeworkClient { public class HomeworkClient {
/**
* Client constructor
*/
public HomeworkClient() { public HomeworkClient() {
// default constructor // default constructor
} }
/**
* local host
*/
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) { /**
* Client constructor
* @param args passed in args
*/
public static void main(String[] args) {
Socket socket = null; Socket socket = null;
InputStream is; InputStream is;
Reader isr; Reader isr;
...@@ -19,7 +33,7 @@ public class HomeworkClient { ...@@ -19,7 +33,7 @@ public class HomeworkClient {
PrintWriter pw; PrintWriter pw;
String serverMessage; String serverMessage;
int clientLoopCount = 0; int clientLoopCount = 0;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
try { try {
...@@ -42,26 +56,28 @@ public class HomeworkClient { ...@@ -42,26 +56,28 @@ public class HomeworkClient {
serverMessage = br.readLine(); serverMessage = br.readLine();
System.out.println("=================================================="); System.out.println("==================================================");
System.out.print("Client loop " + clientLoopCount + ": "); System.out.print("Client loop " + clientLoopCount + ": ");
System.out.println("now we're talking!"); System.out.println("now we're talking!");
System.out.println("The message the server sent was: '" + serverMessage + "'"); System.out.println("The message the server sent was: '" + serverMessage + "'");
Thread.sleep(500l); Thread.sleep(500l);
} }
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
System.err.println("Problem with " + HomeworkClient.class.getName() + " networking:"); System.err.println("Problem with " + HomeworkClient.class.getName() + " networking:");
System.err.println("Error: " + e); System.err.println("Error: " + e);
if (e instanceof java.net.BindException) { if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!"); System.err.println("*** Be sure to stop any other running instances of programs using this port!");
} }
} finally { } finally {
try { try {
if (socket != null) if (socket != null) {
socket.close(); socket.close();
} catch (IOException e) {} }
} catch (IOException e) {
}
System.out.println(); System.out.println();
System.out.println(HomeworkClient.class.getName() + " exit"); System.out.println(HomeworkClient.class.getName() + " exit");
} }
......
package MV3500Cohort2024JulySeptember.homework1.Smith; package MV3500Cohort2024JulySeptember.homework1.Smith;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
/**
* Sever constructor
*/
public class HomeworkServer { public class HomeworkServer {
private static int runningTotal = 0; // Initialize running total private static int runningTotal = 0; // Initialize running total
/**
* Sever constructor
*/
public HomeworkServer() { public HomeworkServer() {
// default constructor // default constructor
} }
/**
* main
* @param args passed in args
*/
public static void main(String[] args) { public static void main(String[] args) {
try { try {
System.out.println(HomeworkServer.class.getName() + " has started..."); System.out.println(HomeworkServer.class.getName() + " has started...");
...@@ -31,13 +41,13 @@ public class HomeworkServer { ...@@ -31,13 +41,13 @@ public class HomeworkServer {
// Read the number sent by the client // Read the number sent by the client
BufferedReader br = new BufferedReader(new InputStreamReader(clientConnectionSocket.getInputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(clientConnectionSocket.getInputStream()));
int clientNumber = Integer.parseInt(br.readLine()); int clientNumber = Integer.parseInt(br.readLine());
// Update the running total // Update the running total
int clientNumnerSqr = clientNumber * clientNumber; int clientNumnerSqr = clientNumber * clientNumber;
runningTotal += clientNumber; runningTotal += clientNumber;
// Send back the updated total // Send back the updated total
ps.println("Client sent: " + clientNumber + ", client number squared was: "+ clientNumnerSqr+", Running total: " + runningTotal); ps.println("Client sent: " + clientNumber + ", client number squared was: " + clientNumnerSqr + ", Running total: " + runningTotal);
System.out.println("Client sent: " + clientNumber + ", Running total: " + runningTotal); System.out.println("Client sent: " + clientNumber + ", Running total: " + runningTotal);
localAddress = clientConnectionSocket.getLocalAddress(); localAddress = clientConnectionSocket.getLocalAddress();
...@@ -47,13 +57,14 @@ public class HomeworkServer { ...@@ -47,13 +57,14 @@ public class HomeworkServer {
System.out.print("Server loop " + serverLoopCount + ": "); System.out.print("Server loop " + serverLoopCount + ": ");
System.out.println(HomeworkServer.class.getName() + " socket pair showing host name, address, port:"); System.out.println(HomeworkServer.class.getName() + " socket pair showing host name, address, port:");
System.out.println(" (( " + System.out.println(" (( "
localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " + + localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( "
remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))"); + remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
if (localAddress.getHostName().equals(localAddress.getHostAddress()) || if (localAddress.getHostName().equals(localAddress.getHostAddress())
remoteAddress.getHostName().equals(remoteAddress.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");
}
ps.flush(); ps.flush();
} }
} }
...@@ -66,4 +77,3 @@ public class HomeworkServer { ...@@ -66,4 +77,3 @@ public class HomeworkServer {
} }
} }
} }
...@@ -8,13 +8,28 @@ import java.io.*; ...@@ -8,13 +8,28 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.util.Scanner; import java.util.Scanner;
/**
* Client Class
* @author tjsus
*/
public class Client { public class Client {
/**
* Client constructor
*/
public Client() { public Client() {
// default constructor // default constructor
} }
/**
* local host
*/
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";
/**
* Main
* @param args passed in args
*/
public static void main(String[] args) { public static void main(String[] args) {
Socket socket = null; Socket socket = null;
InputStream is; InputStream is;
......
...@@ -9,13 +9,25 @@ import java.io.*; ...@@ -9,13 +9,25 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.util.Random; import java.util.Random;
/**
* Client Class
* @author tjsus
*/
public class Server { public class Server {
private static int runningTotal = 0; // Initialize running total private static int runningTotal = 0; // Initialize running total
/**
* Server constructor
*/
public Server() { public Server() {
// default constructor // default constructor
} }
/**
* Main
* @param args passed in args
*/
public static void main(String[] args) { public static void main(String[] args) {
try { try {
System.out.println(Server.class.getName() + " has started..."); System.out.println(Server.class.getName() + " has started...");
......
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