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