Skip to content
Snippets Groups Projects
Commit 9df6bd6c authored by courtneythomerson's avatar courtneythomerson
Browse files

Thomerson Homework 1

parents 8a479d69 d554287a
No related branches found
No related tags found
No related merge requests found
Showing
with 337 additions and 94 deletions
......@@ -27,3 +27,11 @@
/projects/UdpExample1/UdpSender/nbproject/private/private.xml
/projects/MulticastExample/MulticastSenderExample/nbproject/private/private.xml
/projects/TcpExample1/nbproject/private/private.properties
/projects/TcpExample1/dist/
/projects/TcpExample2/dist/
/projects/TcpExample1/nbproject/private
/projects/TcpExample1/build
/projects/TcpExample2/nbproject/private
/projects/TcpExample2/build
/projects/TcpExample3/Client/TcpClient/nbproject/private
/projects/TcpExample3/Server/TcpServer/nbproject/private
......@@ -12,7 +12,7 @@ References and Resources:
* [Netbeans 8.2](http://www.netbeans.org) and [Using Git Support in NetBeans IDE](https://netbeans.org/kb/docs/ide/git.html)
and [Video of Cloning a Git Repository Using NetBeans IDE](https://netbeans.org/kb/docs/ide/git_nb_ssh_screencast.html)
* [Open-DIS Repository](https://github.com/open-dis) and [Distributed Interactive Simulation: The Missing Handbook](https://github.com/open-dis/DISTutorial/blob/master/README.md)
* [Savage Developers Guide](https://savage.nps.edu/Savage/developers.html) resources for [DIS](https://savage.nps.edu/Savage/developers.html#DIS)
* [Savage Developers Guide](https://savage.nps.edu/Savage/developers.html) resources for [Cygwin](https://savage.nps.edu/Savage/developers.html#Cygwin), [DIS](https://savage.nps.edu/Savage/developers.html#DIS) and [telnet](https://savage.nps.edu/Savage/developers.html#telnet)
* [Sequence Diagram](https://en.wikipedia.org/wiki/Sequence_diagram) and [Timing Diagram (UML)](https://en.wikipedia.org/wiki/Timing_diagram_(Unified_Modeling_Language)) on Wikipedia
* [WireShark](https://wireshark.org) and [WireShark Tutorial for Beginners](https://www.youtube.com/watch?v=TkCSr30UojM) video by Anson Alexander
* [X3D-Edit](https://savage.nps.edu/X3D-Edit/#Downloads) as Netbeans Plugin including [DIS PDU Player/Recorder](https://savage.nps.edu/X3D-Edit/images/DisPlayerRecorderPanel.png) and [ESPDU Generator](https://savage.nps.edu/X3D-Edit/images/DisEspduTestPanelDemo.png)
......
No preview for this file type
Students commit and push (and share) their current course work here.
Testing this once again. NOW A MASTER.
Watch out for lazy browsers.
CAPT Severson is a fine American.
Semper Fidelis.
Coffee is good.
I am the Captain now
package CainAssignment1;
import java.io.*;
import java.net.*;
/**
* changed telnet # from 2317 to 2318. This won't affect the protocol handshake
* as long as client inputs the correct telnet #.
*
* telnet localhost 2318
*
* ask for the ip address of the server
* <code>telnet ipOfServersLaptop 2318</code>
*/
public class CainAssignment1 {
public static void main(String[] args) {
try {
int popularityCount = 0; // state
ServerSocket serverSocket = new ServerSocket(2318); // server decides here what port to listen on.
// of interest: often client doesn't care what port it uses locally when connecting to that server port.
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while (true) {
Socket clientConnection = serverSocket.accept(); // blocks! then proceeds once a connection is "accept"ed
/**
* changed connectionCount to popularityCount
*/
popularityCount++;
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server CainAssignment1"); // to remote client
System.out.println("This server response was written by server CainAssignment1"); // to server console
ps.println("You were connection #" + popularityCount + ", by my count");
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort(); // remember the prior question, why are 2 ports different?
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 )) note IPv6
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( "
+ remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("you'er server is blowing up! Now serving #" + popularityCount); // report progress
ps.flush();
clientConnection.close();
}
} catch (Exception e) {
/**
* added to the println for fun
*/
System.out.println("you got all sorts of problems with your networking: " + e);
}
}
}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.io.*;
import java.net.*;
/*
* 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.
*/
/**
*
* @author djfrisco
*/
public class FriscoTcpClient {
public static void main(String[] args)
{
try
{
System.out.println("creating socket");
// We request an IP to connect to ("localhost") and
// port number at that IP (2317). This establishes
// a connection to that IP in the form of the Socket
// object; the server uses a ServerSocket to wait for
// connections.
Socket socket = new Socket("localhost", 2317);
// Read the single line written by the server. We'd
// do things a bit differently if many lines to be read
// from the server, instead of one only.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage = br.readLine();
System.out.println("1 The message the server sent was " + serverMessage);
// Outgoing Messages
OutputStream os = socket.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("bbb report: X, Y, X " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("2 The message the server sent was " + serverMessage);
//os = socket.getOutputStream();
// ps = new PrintStream(os);
ps.println("Final message from client " + System.currentTimeMillis());
serverMessage = br.readLine();
System.out.println("3 The message the server sent was " + serverMessage);
}
catch(Exception e)
{
System.out.println(e);
System.out.println("Problem with client");
}
}
}
package FurrAssignment2;
import java.io.*;
import java.net.*;
/**
* Very slightly more complex than example1. 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 localhost 2317
*
* If you're sophisticated you can contact the instructor's computer
* while running this program.
*
* telnet <ipOfServersLaptop> 2317
*
* And have him display the socket pairs he got.
* @author mcgredo
*/
public class FurrAssignment2
{
public static void main(String[] args)
{
try
{
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
int connectionCount = 0; // state
for(int i=2317; i<10; i++){
ServerSocket serverSocket = new ServerSocket(i);
System.out.println("server established for port #" +i);
}
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while(true)
{
Socket clientConnection = serverSocket.accept(); // blocks! then proceeds once a connection is "accept"ed
connectionCount++; // got another one!
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server TcpExample2"); // to remote client
System.out.println("This server response was written by server TcpExample2"); // to server console
// Print some information locally about the Socket
// connection. This includes the port and IP numbers
// on both sides (the socket pair.)
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
//
// Why is the first IP/port the same, while the second set has
// different ports?
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
System.out.println("got another connection, #" + connectionCount); // report progress
// Notice the use of flush() and close(). Without
// the close() to Socket object may stay open for
// a while after the client has stopped needing this
// connection. Close() explicitly ends the connection.
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking: " + e);
}
}
}
## Homework 1
Deliverables:
1. Apply your own customized version of Assignment 1 and Assignment 2
2. Include comments describing your modifications.
3. Include documentation of one or more sessions, including operation.
4. Create a simple illustration of the communications exchange in a UML Sequence Diagram.
Please see the [README.md](../../README.md) in the \Assignments\ directory for detailed instructions.
## Homework 2
Deliverables:
0. Think of a simple challenge/response protocol that you wish to portray.
1. Apply your own customized version of Assignment 3 showing both Server and Client programs.
2. Include comments describing your modifications.
3. Include documentation of one or more sessions, including operation.
4. Create a simple illustration of the communications exchange in a UML Sequence Diagram.
Please see the [README.md](../../README.md) in the Assignments directory for detailed instructions.
\ No newline at end of file
......@@ -9,6 +9,7 @@ Use Netbeans to upload/update your homework assignments as follows:
1. *context menu:* **Git > Remote > Pull from Upstream** to first always ensure you update your repository
1. Save into your local directory for `projects/Assignments/COURSE_IDENTIFIER/homework1` (as appropriate)
* For example 2018JanuaryMarch or 2018JulySeptember
1. Select file of interest in Netbeans tab for Files
1. *context menu:* **Refactor/Rename** and take spaces out of file name (gets wacky on various operating systems, email etc.)
1. Ensure Java classes and source files start with your last name
......
File deleted
compile.on.save=true
user.properties.file=/Users/courtneythomerson/Library/Application Support/NetBeans/8.2/build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>
......@@ -48,8 +48,8 @@ public class TcpExample
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("This client response was written by server TcpExample1"); // to remote client
System.out.println("This server response was written by server TcpExample1"); // to server console
ps.println("This client response was written by server TcpExample1"); // to remote client
System.out.println("This server response was written by server TcpExample1"); // to server console
// "flush()" in important in that it forces a write
// across what is in fact a slow connection
......@@ -61,8 +61,5 @@ public class TcpExample
{
System.out.println("problem with networking: " + e);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="TcpExample2" default="default" basedir=".">
<description>Builds, tests, and runs the project TcpExample2.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="TcpExample2-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="TcpExample2" default="default" basedir=".">
<description>Builds, tests, and runs the project TcpExample2.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="TcpExample2-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
File deleted
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