Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
911d423
All source code
rutgershealthhackathon67-ops Oct 21, 2025
7d8ede9
UCID and steps
rutgershealthhackathon67-ops Oct 21, 2025
61c637a
else if statement
rutgershealthhackathon67-ops Oct 21, 2025
48501b8
Added ucid and date
rutgershealthhackathon67-ops Oct 21, 2025
8c332c9
one other method added
rutgershealthhackathon67-ops Oct 21, 2025
1f91229
date and ucid
rutgershealthhackathon67-ops Oct 21, 2025
9741469
case flip added
rutgershealthhackathon67-ops Oct 21, 2025
615f824
Fixed package errors
rutgershealthhackathon67-ops Oct 21, 2025
4edb2c7
added random
rutgershealthhackathon67-ops Oct 21, 2025
524a656
date and ucid
rutgershealthhackathon67-ops Oct 21, 2025
94ca482
Handle messages
rutgershealthhackathon67-ops Oct 21, 2025
9d40091
add ucid and date
rutgershealthhackathon67-ops Oct 21, 2025
41ceb2b
else if statement added
rutgershealthhackathon67-ops Oct 21, 2025
98dd649
added steps ucid and date
rutgershealthhackathon67-ops Oct 21, 2025
20cbb1f
another case statement
rutgershealthhackathon67-ops Oct 22, 2025
f67c21d
date, ucid and steps
rutgershealthhackathon67-ops Oct 22, 2025
eda60b2
Shuffle is else statement
rutgershealthhackathon67-ops Oct 22, 2025
d26314a
date and ucid and steps
rutgershealthhackathon67-ops Oct 22, 2025
2f71ea1
case statement for shuffle
rutgershealthhackathon67-ops Oct 22, 2025
33cd988
steps, ucid, and date
rutgershealthhackathon67-ops Oct 22, 2025
09f7918
method for shuffle
rutgershealthhackathon67-ops Oct 22, 2025
2feabed
all m5/m4 files
rutgershealthhackathon67-ops Nov 3, 2025
dc1041a
project base files
rutgershealthhackathon67-ops Nov 3, 2025
c54b162
renamed files
rutgershealthhackathon67-ops Nov 3, 2025
e9be04d
renamed packages
rutgershealthhackathon67-ops Nov 3, 2025
0bd21c7
fixed missing colon
rutgershealthhackathon67-ops Nov 3, 2025
80601cd
removed semicolon
rutgershealthhackathon67-ops Nov 3, 2025
78aea2d
color package fix
rutgershealthhackathon67-ops Nov 3, 2025
5802bbe
fixing pacakge errors
rutgershealthhackathon67-ops Nov 3, 2025
697d07f
re added files
rutgershealthhackathon67-ops Nov 3, 2025
90de15e
fixing
rutgershealthhackathon67-ops Nov 3, 2025
b1fc732
changes
rutgershealthhackathon67-ops Nov 4, 2025
1479391
Added for milestone2
rutgershealthhackathon67-ops Nov 26, 2025
ad13dd1
Added few comments
rutgershealthhackathon67-ops Nov 26, 2025
ce37a93
All payload files
rutgershealthhackathon67-ops Nov 26, 2025
9db6d88
comments added
rutgershealthhackathon67-ops Nov 26, 2025
28e6df1
New files added and old ones modififed
rutgershealthhackathon67-ops Nov 26, 2025
bad915b
comments made
rutgershealthhackathon67-ops Nov 26, 2025
2119e8a
comments added
rutgershealthhackathon67-ops Nov 26, 2025
f96db7f
Milstone2 ready
rutgershealthhackathon67-ops Nov 26, 2025
7b300c2
Added exception files for milestone2
rutgershealthhackathon67-ops Nov 26, 2025
c60eb27
new room files for milestone2
rutgershealthhackathon67-ops Nov 26, 2025
4e3602d
new comments added
rutgershealthhackathon67-ops Nov 26, 2025
430825f
Milestone 2 Done
rutgershealthhackathon67-ops Nov 26, 2025
c6d5238
MileStone 2 Server files
rutgershealthhackathon67-ops Nov 26, 2025
b2c8778
Comments added
rutgershealthhackathon67-ops Nov 26, 2025
d1eb5d5
MileStone 2 ready
rutgershealthhackathon67-ops Nov 26, 2025
6cdfeea
MileStone2 Done
rutgershealthhackathon67-ops Nov 26, 2025
20f5d27
bash files
rutgershealthhackathon67-ops Nov 26, 2025
462c350
ucid comments
rutgershealthhackathon67-ops Nov 26, 2025
f63b8e8
ucid added
rutgershealthhackathon67-ops Nov 26, 2025
d34501e
ucid added
rutgershealthhackathon67-ops Nov 26, 2025
82a9326
ucid added
rutgershealthhackathon67-ops Nov 26, 2025
e9d491f
changes
rutgershealthhackathon67-ops Nov 27, 2025
be5e0e7
fixed the ready function
rutgershealthhackathon67-ops Dec 1, 2025
8a675d8
changes
rutgershealthhackathon67-ops Dec 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions M4/Part1/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package M4.Part1;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Demoing single direction of Client sending data to a Server
*/
public class Client {

private Socket server = null;
private PrintWriter out = null;
final Pattern ipAddressPattern = Pattern
.compile("/connect\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{3,5})"); // 192.168.0.2:3000
final Pattern localhostPattern = Pattern.compile("/connect\\s+(localhost:\\d{3,5})"); // localhost:3000
private boolean isRunning = false;

public Client() {
System.out.println("Client Created");
}

public boolean isConnected() {
if (server == null) {
return false;
}
// https://stackoverflow.com/a/10241044
// Note: these check the client's end of the socket connect; therefore they
// don't really help determine
// if the server had a problem and is just for lesson's sake
return server.isConnected() && !server.isClosed() && !server.isInputShutdown() && !server.isOutputShutdown();

}

/**
* Takes an ip address and a port to attempt a socket connection to a server.
*
* @param address
* @param port
* @return true if connection was successful
*/
private boolean connect(String address, int port) {
try {
server = new Socket(address, port);
// channel to send to server
out = new PrintWriter(server.getOutputStream(), true);
// channel to list to server
System.out.println("Client connected");
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return isConnected();
}

/**
* <p>
* Check if the string contains the <i>connect</i> command
* followed by an ip address and port or localhost and port.
* </p>
* <p>
* Example format: 123.123.123:3000
* </p>
* <p>
* Example format: localhost:3000
* </p>
* https://www.w3schools.com/java/java_regex.asp
*
* @param text
* @return
*/
private boolean isConnection(String text) {
// https://www.w3schools.com/java/java_regex.asp
Matcher ipMatcher = ipAddressPattern.matcher(text);
Matcher localhostMatcher = localhostPattern.matcher(text);
return ipMatcher.matches() || localhostMatcher.matches();
}

/**
* Controller for handling various text commands.
* <p>
* Add more here as needed
* </p>
*
* @param text
* @return true if a text was a command or triggered a command
*/
private boolean processClientCommand(String text) {
if (isConnection(text)) {
// replaces multiple spaces with single space
// splits on the space after connect (gives us host and port)
// splits on : to get host as index 0 and port as index 1
String[] parts = text.trim().replaceAll(" +", " ").split(" ")[1].split(":");
connect(parts[0].trim(), Integer.parseInt(parts[1].trim()));
return true;
} else if ("/quit".equalsIgnoreCase(text)) {
isRunning = false;
return true;
}
return false;
}

public void start() throws IOException {

System.out.println("Client starting");
try (Scanner si = new Scanner(System.in);) {
String line = "";
isRunning = true;
while (isRunning) {
try {
System.out.println("Waiting for input");
line = si.nextLine();
if (!processClientCommand(line)) {
if (isConnected()) {
out.println(line);
// https://stackoverflow.com/a/8190411
// you'll notice it triggers on the second request after server socket closes
if (out.checkError()) {
System.out.println("Connection to server may have been lost");
}
} else {
System.out.println("Not connected to server");
}
}
} catch (Exception e) {
System.out.println("Connection dropped");
break;
}
}
System.out.println("Exited loop");
} catch (Exception e) {
System.out.println("Exception from start()");
e.printStackTrace();
} finally {
close();
}
}

private void close() {
try {
System.out.println("Closing output stream");
out.close();
} catch (NullPointerException ne) {
System.out.println("Server was never opened so this exception is ok");
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("Closing connection");
server.close();
System.out.println("Closed socket");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException ne) {
System.out.println("Server was never opened so this exception is ok");
}
}

public static void main(String[] args) {
Client client = new Client();

try {
// if start is private, it's valid here since this main is part of the class
client.start();
} catch (IOException e) {
System.out.println("Exception from main()");
e.printStackTrace();
}
}
}
56 changes: 56 additions & 0 deletions M4/Part1/Server.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package M4.Part1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
private int port = 3000;

private void start(int port) {
this.port = port;
System.out.println("Listening on port " + this.port);
// server listening
try (ServerSocket serverSocket = new ServerSocket(port);
// client wait
Socket client = serverSocket.accept(); // blocking;

// read from client
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));) {

System.out.println("Client connected, waiting for message");
String fromClient = "";
while ((fromClient = in.readLine()) != null) {
if ("/kill server".equalsIgnoreCase(fromClient)) {
// normally you wouldn't have a remote kill command, this is just for example
// sake
System.out.println("Client killed server");
break;
} else {
System.out.println("From client: " + fromClient);
}
}
} catch (IOException e) {
System.out.println("Exception from start()");
e.printStackTrace();
} finally {
System.out.println("closing server socket");
}
}

public static void main(String[] args) {
System.out.println("Server Starting");
Server server = new Server();
int port = 3000;
try {
port = Integer.parseInt(args[0]);
} catch (Exception e) {
// can ignore, will either be index out of bounds or type mismatch
// will default to the defined value prior to the try/catch
}
server.start(port);
System.out.println("Server Stopped");
}
}
Loading