Skip to content
Snippets Groups Projects
Commit db25b126 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

zip unrecoverable homework project submission

parent ea50ce28
No related branches found
No related tags found
No related merge requests found
Showing
with 4 additions and 164 deletions
package MV3500Cohort2018JanuaryMarch;
/** /**
* ExampleSimpleSimulation program-modification homework assignment supporting the NPS MOVES MV3500 Networked Graphics course. * Student homework assignments produced as part of the NPS MOVES MV3500 Networked Graphics course.
* *
* @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments">networkedGraphicsMV3500 assignments</a> * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments">networkedGraphicsMV3500 assignments</a>
* @see java.lang.Package * @see java.lang.Package
...@@ -7,4 +9,4 @@ ...@@ -7,4 +9,4 @@
* @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java">StackOverflow: how-do-i-document-packages-in-java</a> * @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java">StackOverflow: how-do-i-document-packages-in-java</a>
*/ */
package MV3500Cohort2022MayJune.homework2.Royer;
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>RoyerHomework2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
package royer.homework2;
import java.net.*;
import java.io.*;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Homework example
* @author Nick Royer
*/
public class TCPPeer {
private ServerSocket server_socket = null;
private Socket client_socket = null;
private PrintWriter out_stream = null;
private BufferedReader in_stream = null;
private boolean is_server = true;
public boolean isServer() {
return is_server;
}
public TCPPeer(int port, String ip) throws IOException {
is_server = (ip.equals(""));
if (is_server) {
server_socket = new ServerSocket(port);
client_socket = server_socket.accept();
} else {
// Client
client_socket = new Socket(ip, port);
}
in_stream = new BufferedReader(new InputStreamReader(client_socket.getInputStream()));
out_stream = new PrintWriter(client_socket.getOutputStream(), true);
should_stop.set(false);
start();
}
void start() {
if (is_server) {
while(!should_stop.get()) {
try {
String msg = in_stream.readLine();
// if (msg == null || msg.equals(""))
// continue;
System.out.println("Server received \"" + msg + "\"");
out_stream.println("OK");
if (msg.equals("--quit"))
stop_connection();
} catch (IOException ex) {
}
}
}
}
private final AtomicBoolean should_stop = new AtomicBoolean(false);
public void stop_connection() {
should_stop.set(true);
}
public TCPPeer(int port) throws IOException {
this(port, "");
}
public void close() throws IOException {
System.out.println("Closing " + (is_server ? "Server" : "Client"));
in_stream.close();
out_stream.close();
client_socket.close();
if (is_server) {
server_socket.close();
} else {
}
}
public String send(String msg) throws IOException {
out_stream.println(msg);
String response = in_stream.readLine();
System.out.println((is_server ? "Server" : "Client") + " sending \"" + msg + "\": " + response);
return response;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package royer.homework2;
/**
* Homework example
* @author Nicholas Royer
*/
public class Tester {
private static class ServerThread extends Thread {
private TCPPeer server = null;
int port = 0;
public ServerThread(int port) {
super();
this.port = port;
}
@Override
public void run() {
try {
server = new TCPPeer(port);
server.close();
Thread.currentThread().interrupt();
} catch (Exception ioex) {
System.err.println(ioex.toString());
}
}
}
public static void main(String[] args) {
int test_port = 6668;
try {
System.out.println("Setting up");
ServerThread st = new ServerThread(test_port);
st.start();
TCPPeer client = new TCPPeer(test_port, "127.0.0.1");
System.out.println("Setup complete");
client.send("Test");
client.send("--quit");
client.close();
st.join();
System.out.println("Done");
} catch (Exception ex) {
System.err.println(ex.toString());
}
}
}
royer/homework2/Tester.class
royer/homework2/TCPPeer.class
/home/nick/Documents/NPS/Quarter 4/MV3500/Homework 2/RoyerHomework2/src/main/java/royer/homework2/Tester.java
/home/nick/Documents/NPS/Quarter 4/MV3500/Homework 2/RoyerHomework2/src/main/java/royer/homework2/TCPPeer.java
nothing yet
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