diff --git a/README.md b/README.md index 83a59edc67c234697b64e66c89845e64faf2a4eb..134058e80a625f880d6abcc85228e36275ebfcc2 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,5 @@ and [Video of Cloning a Git Repository Using NetBeans IDE](https://netbeans.org/ * [Savage Developers Guide](https://savage.nps.edu/Savage/developers.html) resources for [DIS](https://savage.nps.edu/Savage/developers.html#DIS) * UML [Sequence diagram](https://en.wikipedia.org/wiki/Sequence_diagram) 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 +* [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) +* [X3D for Web Authors](http://x3dgraphics.com) book, examples and slidesets including [X3D Distributed Interactive Simulation (DIS)](http://x3dgraphics.com/slidesets/X3dForAdvancedModeling/DistributedInteractiveSimulation.pdf) diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngBlank-MV3500finalPresentation.pptx b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngBlank-MV3500finalPresentation.pptx new file mode 100644 index 0000000000000000000000000000000000000000..dfe24b54a1f01173613084a8d9c095ea43e0bd0b Binary files /dev/null and b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngBlank-MV3500finalPresentation.pptx differ diff --git a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionReceiver.java b/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionReceiver.java deleted file mode 100644 index f756d49fcf0b7b6f9285908eafa5e3b89599453a..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionReceiver.java +++ /dev/null @@ -1,39 +0,0 @@ -//package PositionClient; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.net.Socket; -import java.net.UnknownHostException; - -/** - * - * @author AJSNELL - */ -public class ConardSnellPositionReceiver { - /** - * @param args the command line arguments - * @throws java.io.IOException - */ - public static void main(String[] args) throws IOException { - String hostName = args[0]; - try (Socket clientSocket = new Socket(hostName, 8005); - PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); - BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) { - String userInput; - out.println("unit id: 1\nunit pos: 11S MS 4859 9849"); - while ((userInput = stdIn.readLine()) != null) { - out.println(userInput); - System.out.println("from client: " + in.readLine()); - } - } catch (UnknownHostException e) { - System.err.println("Don't know about host " + hostName); - System.exit(1); - } catch (IOException e) { - System.err.println("Couldn't get I/O for the connection to " + hostName); - System.exit(1); - } - } -} \ No newline at end of file diff --git a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionSender.java b/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionSender.java deleted file mode 100644 index 4a77d3525650e99e84442cdf592556cdfd3967b7..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellPositionSender.java +++ /dev/null @@ -1,30 +0,0 @@ -//package positionserver; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.ServerSocket; -import java.net.Socket; -import java.io.PrintWriter; - -public class ConardSnellPositionSender { - /** - * @param args the command line arguments - * @throws java.io.IOException - */ - public static void main(String[] args) throws IOException { - try (ServerSocket serverSocket = new ServerSocket(8005); - Socket clientSocket = serverSocket.accept(); - PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); - BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));) { - System.out.println("Client connected on port 8005"); - String inputLine; - while ((inputLine = in.readLine()) != null) { - System.out.println("Received message: " + inputLine + " from " + clientSocket.toString()); - out.println(inputLine); - } - } catch (IOException e) { - System.out.println("Exception when trying to listen on port 8005"); - } - } -} \ No newline at end of file diff --git a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellREADME.md b/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellREADME.md deleted file mode 100644 index a704e52cd0e75e5a801b3642b756d0b74085a1da..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardSnellREADME.md +++ /dev/null @@ -1,7 +0,0 @@ -## Final Course Projects 2018March - -Create a dedicated subdirectory for each individual or team project. - -Example: `SmithJones` - -See the course syllabus for details on how to document your project. diff --git a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpClient.java b/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpClient.java deleted file mode 100644 index 37d674b3a4f76a38c24bb2852217e20b019838f9..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpClient.java +++ /dev/null @@ -1,52 +0,0 @@ -//package tcpclient; - -import java.io.*; -import java.net.*; - -/** - * Before, we always used telnet to connect to the server. We - * are now writing our own program to do the connection. - * - * As you will see, when we run this after we start the server - * we will see the same string telnet printed, sent by the server. - * The output at the server will show different socket pairs for - * each time we ran it. - * - * @author mcgredo - */ -public class ConardTcpClient { - - - 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("What is your location? " + serverMessage); - - } - catch(Exception e) - { - System.out.println(e); - System.out.println("Problem with client"); - } - - } - -} diff --git a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpServer.java b/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpServer.java deleted file mode 100644 index 13af5422902228c72ed99ff68af02284849968fb..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/ConardSnell/ConardTcpServer.java +++ /dev/null @@ -1,84 +0,0 @@ -//package tcpserver; - -import java.io.*; -import java.net.*; - -/** - * Very slightly more complex than example1. A complete copy of - * example 2. 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 ConardTcpServer -{ - - 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. - - ServerSocket serverSocket = new ServerSocket(2317); -// System.out.println("socketCreated"); - - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while(true) - { - Socket clientConnection = serverSocket.accept(); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - ps.println("My location is 1,2,5"); - - // 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 + " ))"); - - // 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"); - } - - } - -} \ No newline at end of file diff --git a/projects/Assignments/FinalProjects/2018March/Hanley/HanleyMV3500FinalPresentation(ReadCsvToSendPDU).pptx b/projects/Assignments/FinalProjects/2018March/Hanley/HanleyMV3500FinalPresentation(ReadCsvToSendPDU).pptx new file mode 100644 index 0000000000000000000000000000000000000000..6ec8d5e755cfddbac0e235fe32381d5b07f33f81 Binary files /dev/null and b/projects/Assignments/FinalProjects/2018March/Hanley/HanleyMV3500FinalPresentation(ReadCsvToSendPDU).pptx differ diff --git a/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/README.md b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/README.md new file mode 100644 index 0000000000000000000000000000000000000000..10a791462038cfa4abdc40d63665eea32fe42645 --- /dev/null +++ b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/README.md @@ -0,0 +1,46 @@ +MV3500 - Internetwork Communications and Simulation +Prof. Dr. Don Brutzman + +Landas, Enrico +Tacket, Cody +Yamashita de Moura, Douglas + +Final Project +Adapt a Unity or Other Program to Emit PDUs Using Open-DIS C# Binding + +Two C# scripts, Sender.cs and Receiver.cs, were created to send and receive +PDUs, respectively. The following data is included: + +Sender.cs +- IP Address: 239.1.2.3 +- Port: 3000 +- EntityID.Entity: 1 + +Receiver.cs +- IP Address: 239.1.2.3 +- Port: 3000 +- EntityID.Entity to be processed: anyone different from 1 + +For the project purpose, the scripts were implemented in such a way that all +multicast information is enclosed on the scripts and only selected information +is processed and printed on the screen. Each computer will print the data +from the entity that is different from the one it is sending. + +Unity Project +- The Unity package can be downloaded from: +- https://owncloud.nps.edu/owncloud/index.php/s/mewLa2BUEWhucPa + +Video +- A video showing two applications working can be found at the Video folder +of the Unity package + +TO-DO List +- Create an Unity interface to receive input data: IP address, port, etc +- Transform the object location to real world location (using latitude, +longitude and altitude) +- Replace the 'InvokeRepeating' method using a thread (when creating a sender +and a client on the same computer, this method may not work properly, i.e., +the interval between the calls could be different from the expected) +- Implement creation of the received object on the Receiver.cs (or other +interface to be created) +- Implement control of the object (NavySeal guy) using keyboard/mouse \ No newline at end of file diff --git a/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Receiver.cs b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Receiver.cs new file mode 100644 index 0000000000000000000000000000000000000000..8504e9fd0d29c75f99b2a87d8ad096203150c25d --- /dev/null +++ b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Receiver.cs @@ -0,0 +1,100 @@ +using System; +using UnityEngine; +using System.Net; +using System.Net.Sockets; +using OpenDis.Core; +using OpenDis.Dis1998; +using OpenDis.Enumerations; +using UnityEngine.UI; + +public class Receiver : MonoBehaviour { + + UdpClient client; + IPEndPoint localEp; + EntityStatePdu newEntityStatePDU; + IPAddress multicastaddress; + PduProcessor pduProcessor; + int PDU_TYPE_POSITION = 2; + public GameObject locationText; + Vector3Double location; + EntityID entityID; + EntityType entityType; + + // Use this for initialization + public void onClick () { + + Debug.Log("Start receiving..."); + + // Create UDP Client to receive data + client = new UdpClient(); + client.ExclusiveAddressUse = false; + localEp = new IPEndPoint(IPAddress.Any, 3000); + client.Client.SetSocketOption(SocketOptionLevel.Socket, + SocketOptionName.ReuseAddress, true); + client.ExclusiveAddressUse = false; + client.Client.Bind(localEp); + multicastaddress = IPAddress.Parse("239.1.2.3"); + client.JoinMulticastGroup(multicastaddress); + locationText = GameObject.FindGameObjectWithTag("ReceiverLocationText"); + + // Broadcast IP - Client + InvokeRepeating("BroadcastClientIP", 0, 1f); + } + + // Receive data + void BroadcastClientIP() + { + try + { + if(client.Available > 0) + { + // Blocks until a message returns on this socket from a remote host. + Byte[] receivedBytes = client.Receive(ref localEp); + + if(receivedBytes != null && receivedBytes.Length > 0) + { + try + { + PduType pduType = (PduType)receivedBytes[PDU_TYPE_POSITION]; + Pdu pdu = PduProcessor.UnmarshalRawPdu(pduType, receivedBytes, Endian.Big); + switch ((PduType)pdu.PduType) + { + case PduType.EntityState: + ProcessEntityStatePdu((EntityStatePdu)pdu); + SetLocationText(); + break; + default: + break; + } + } catch (Exception e) + { + Debug.LogError(e.ToString()); + } + } + } + } + catch (Exception e) + { + Debug.LogError(e.ToString()); + } + } + + // Process Entity State PDU + void ProcessEntityStatePdu(EntityStatePdu espdu) + { + entityID = espdu.EntityID; + entityType = espdu.EntityType; + location = espdu.EntityLocation; + } + + // Print NavySeal info on screen + void SetLocationText() + { + if (entityID.Entity != 1) + { + locationText.GetComponent<Text>().text = String.Format("NAVY SEAL RECEIVER\nID: {0}\nCountry: {1}\nCategory: {2}\nLocation: ({3}, {4}, {5})", entityID.Entity.ToString(), entityType.Country.ToString(), entityType.Category.ToString(), location.X.ToString("F2"), location.Y.ToString("F2"), location.Z.ToString("F2")); + Debug.Log(String.Format("NAVY SEAL RECEIVER\nID: {0}\nCountry: {1}\nCategory: {2}\nLocation: ({3}, {4}, {5})", entityID.Entity.ToString(), entityType.Country.ToString(), entityType.Category.ToString(), location.X.ToString("F2"), location.Y.ToString("F2"), location.Z.ToString("F2"))); + } + } + +} diff --git a/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Sender.cs b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Sender.cs new file mode 100644 index 0000000000000000000000000000000000000000..fb98d126cf787192e6fb9640112bd24686d5e8a3 --- /dev/null +++ b/projects/Assignments/FinalProjects/2018March/LandasTackettDeMoura/Sender.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using System.Net; +using System.Net.Sockets; +using System.Text; +using OpenDis.Dis1998; +using OpenDis.Core; +using System.IO; +using System.Threading; +using UnityEngine.UI; + +public class Sender : MonoBehaviour { + + UdpClient sender; + string serverIP; + int broadcastPort = 3000; + IPEndPoint remoteEP; + string data = ""; + public GameObject locationText; + EntityStatePdu espdu; + EntityID entityID; + EntityType entityType; + + //NavySeal object and position + public GameObject NavySeal; + private double x; + private double y; + private double z; + + void Start() { + + // Get Navy Seal object + NavySeal = GameObject.FindGameObjectWithTag("NavySealPrefab"); + + // Create new entity state and set exercise + espdu = new EntityStatePdu(); + espdu.ExerciseID = 1; + + // Create and set entity marking + Marking myMarking = new Marking(); + myMarking.CharacterSet = 1; + String markingTest = "Test"; + myMarking.Characters = Encoding.UTF8.GetBytes(markingTest); + espdu.Marking = myMarking; + + // Get time stamp + espdu.Timestamp = (uint)DateTimeOffset.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + + // Set entity ID parameters + entityID = espdu.EntityID; + entityID.Site = 1; + entityID.Application = 1; + entityID.Entity = 1; + + // Set entity type parameters + entityType = espdu.EntityType; + entityType.EntityKind = 1; + entityType.Country = 225; + entityType.Domain = 1; + entityType.Category = 1; + entityType.Subcategory = 20; + entityType.Specific = 3; + + locationText = GameObject.FindGameObjectWithTag("SenderLocationText"); + } + + // Use this for initialization + public void onClick () { + Debug.Log("Starting multicasting..."); + + //Create UDP Client for broadcasting the server + sender = new UdpClient(); + IPAddress groupIP = IPAddress.Parse("239.1.2.3"); + sender.JoinMulticastGroup(groupIP); + remoteEP = new IPEndPoint(groupIP, broadcastPort); + + //Broadcast IP - Server + InvokeRepeating("BroadcastServerIP", 0, 1f); + } + + // Prepare and send data + void BroadcastServerIP() + { + // Get and print entity position + x = NavySeal.transform.position.x; + y = NavySeal.transform.position.y; + z = NavySeal.transform.position.z; + //Debug.Log(NavySeal.transform.position); + + // Set entity location + Vector3Double location = espdu.EntityLocation; + location.X = x; + location.Y = y; + location.Z = z; + + // Get time stamp + espdu.Timestamp = (uint)DateTimeOffset.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + + //Prepare output + DataOutputStream dos = new DataOutputStream(Endian.Big); + espdu.MarshalAutoLengthSet(dos); + + // Transmit messages + byte[] buffer = dos.ConvertToBytes(); + sender.Send(buffer, buffer.Length, remoteEP); + //Debug.Log(Time.realtimeSinceStartup + ": Sent broadcast data: " + espdu); + + SetLocationText(); + } + + // Print NavySeal info on screen + void SetLocationText() + { + locationText.GetComponent<Text>().text = String.Format("NAVY SEAL SENDER\nID: {0}\nCountry: {1}\nCategory: {2}\nLocation: ({3}, {4}, {5})", entityID.Entity.ToString(), entityType.Country.ToString(), entityType.Category.ToString(), x.ToString("F2"), y.ToString("F2"), z.ToString("F2")); + Debug.Log(String.Format("NAVY SEAL SENDER\nID: {0}\nCountry: {1}\nCategory: {2}\nLocation: ({3}, {4}, {5})", entityID.Entity.ToString(), entityType.Country.ToString(), entityType.Category.ToString(), x.ToString("F2"), y.ToString("F2"), z.ToString("F2"))); + } + +} diff --git a/projects/Assignments/FinalProjects/README.md b/projects/Assignments/FinalProjects/README.md index 902eb6cc6e8b1b1b07790028bf4248d195268b65..9c68fc1349c97a3311b9191937a19e6500bb7e97 100644 --- a/projects/Assignments/FinalProjects/README.md +++ b/projects/Assignments/FinalProjects/README.md @@ -1,4 +1,4 @@ -## Final Course Projects +## Final Course Project Landas and Tackett Create a dedicated subdirectory for each individual or team project. diff --git a/projects/Assignments/homework1/ConardTcpClient.java b/projects/Assignments/homework1/ConardTcpClient.java deleted file mode 100644 index 37d674b3a4f76a38c24bb2852217e20b019838f9..0000000000000000000000000000000000000000 --- a/projects/Assignments/homework1/ConardTcpClient.java +++ /dev/null @@ -1,52 +0,0 @@ -//package tcpclient; - -import java.io.*; -import java.net.*; - -/** - * Before, we always used telnet to connect to the server. We - * are now writing our own program to do the connection. - * - * As you will see, when we run this after we start the server - * we will see the same string telnet printed, sent by the server. - * The output at the server will show different socket pairs for - * each time we ran it. - * - * @author mcgredo - */ -public class ConardTcpClient { - - - 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("What is your location? " + serverMessage); - - } - catch(Exception e) - { - System.out.println(e); - System.out.println("Problem with client"); - } - - } - -} diff --git a/projects/Assignments/homework1/ConardTcpServer.java b/projects/Assignments/homework1/ConardTcpServer.java deleted file mode 100644 index 13af5422902228c72ed99ff68af02284849968fb..0000000000000000000000000000000000000000 --- a/projects/Assignments/homework1/ConardTcpServer.java +++ /dev/null @@ -1,84 +0,0 @@ -//package tcpserver; - -import java.io.*; -import java.net.*; - -/** - * Very slightly more complex than example1. A complete copy of - * example 2. 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 ConardTcpServer -{ - - 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. - - ServerSocket serverSocket = new ServerSocket(2317); -// System.out.println("socketCreated"); - - // Loop, infinitely, waiting for client connections. - // Stop the program somewhere else. - while(true) - { - Socket clientConnection = serverSocket.accept(); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - ps.println("My location is 1,2,5"); - - // 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 + " ))"); - - // 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"); - } - - } - -} \ No newline at end of file diff --git a/projects/Assignments/homework2/TackettMulticastSender.java b/projects/Assignments/homework2/TackettMulticastSender.java index 6942dfa6743786eb8f51464d0ccadab51a956aaa..e500d7f913b32de639edf2e538c4a44867eff1c3 100644 --- a/projects/Assignments/homework2/TackettMulticastSender.java +++ b/projects/Assignments/homework2/TackettMulticastSender.java @@ -12,7 +12,7 @@ import java.net.*; public class TackettMulticastSender { - public static final String MULTICAST_ADDRESS = "239.1.2.15"; + public static final String MULTICAST_ADDRESS = "172.20.144.145"; public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ public static final int TTL = 10; diff --git a/projects/Assignments/homework3/EspduSender_1.java b/projects/Assignments/homework3/EspduSender_1.java deleted file mode 100644 index 1758b36b3729ed862fe22b98ad68eef64eeaf2f1..0000000000000000000000000000000000000000 --- a/projects/Assignments/homework3/EspduSender_1.java +++ /dev/null @@ -1,323 +0,0 @@ -package edu.nps.moves.examples; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.CoordinateConversions; -import edu.nps.moves.disutil.DisTime; - -/** - * Creates and sends ESPDUs in IEEE binary format. - * - * @author DMcG - */ -public class EspduSender -{ - public static final int NUMBER_TO_SEND = 5000; - - public enum NetworkMode{UNICAST, MULTICAST, BROADCAST}; - - /** default multicast group we send on */ - public static final String DEFAULT_MULTICAST_GROUP="239.1.2.3"; - - /** Port we send on */ - public static final int DIS_DESTINATION_PORT = 3000; - -/** Possible system properties, passed in via -Dattr=val - * networkMode: unicast, broadcast, multicast - * destinationIp: where to send the packet. If in multicast mode, this can be mcast. - * To determine bcast destination IP, use an online bcast address - * caclulator, for example http://www.remotemonitoringsystems.ca/broadcast.php - * If in mcast mode, a join() will be done on the mcast address. - * port: port used for both source and destination. - * @param args - */ -public static void main(String args[]) -{ - /** an entity state pdu */ - EntityStatePdu espdu = new EntityStatePdu(); - MulticastSocket socket = null; - DisTime disTime = DisTime.getInstance(); - int alternator = -1; - - // ICBM coordinates for my office - double lat = 36.595517; - double lon = -121.877000; - - - // Default settings. These are used if no system properties are set. - // If system properties are passed in, these are over ridden. - int port = DIS_DESTINATION_PORT; - NetworkMode mode = NetworkMode.BROADCAST; - InetAddress destinationIp = null; - - try - { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_GROUP); - } - catch(Exception e) - { - System.out.println(e + " Cannot create multicast address"); - System.exit(0); - } - - // All system properties, passed in on the command line via -Dattribute=value - Properties systemProperties = System.getProperties(); - - // IP address we send to - String destinationIpString = systemProperties.getProperty("destinationIp"); - - // Port we send to, and local port we open the socket on - String portString = systemProperties.getProperty("port"); - - // Network mode: unicast, multicast, broadcast - String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast - - - // Set up a socket to send information - try - { - // Port we send to - if(portString != null) - port = Integer.parseInt(portString); - - socket = new MulticastSocket(port); - - // Where we send packets to, the destination IP address - if(destinationIpString != null) - { - destinationIp = InetAddress.getByName(destinationIpString); - } - - // Type of transport: unicast, broadcast, or multicast - if(networkModeString != null) - { - if(networkModeString.equalsIgnoreCase("unicast")) - mode = NetworkMode.UNICAST; - else if(networkModeString.equalsIgnoreCase("broadcast")) - mode = NetworkMode.BROADCAST; - else if(networkModeString.equalsIgnoreCase("multicast")) - { - mode = NetworkMode.MULTICAST; - if(!destinationIp.isMulticastAddress()) - { - throw new RuntimeException("Sending to multicast address, but destination address " + destinationIp.toString() + "is not multicast"); - } - - socket.joinGroup(destinationIp); - - } - } // end networkModeString - } - catch(Exception e) - { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - // Initialize values in the Entity State PDU object. The exercise ID is - // a way to differentiate between different virtual worlds on one network. - // Note that some values (such as the PDU type and PDU family) are set - // automatically when you create the ESPDU. - espdu.setExerciseID((short)1); - - // The EID is the unique identifier for objects in the world. This - // EID should match up with the ID for the object specified in the - // VMRL/x3d/virtual world. - EntityID eid = espdu.getEntityID(); - eid.setSite(1); // 0 is apparently not a valid site number, per the spec - eid.setApplication(1); - eid.setEntity(2); - - // Set the entity type. SISO has a big list of enumerations, so that by - // specifying various numbers we can say this is an M1A2 American tank, - // the USS Enterprise, and so on. We'll make this a tank. There is a - // separate project elsehwhere in this project that implements DIS - // enumerations in C++ and Java, but to keep things simple we just use - // numbers here. - EntityType entityType = espdu.getEntityType(); - entityType.setEntityKind((short)1); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(225); // USA - entityType.setDomain((short)1); // Land (vs air, surface, subsurface, space) - entityType.setCategory((short)1); // Tank - entityType.setSubcategory((short)1); // M1 Abrams - entityType.setSpec((short)3); // M1A2 Abrams - - - Set<InetAddress> bcastAddresses = getBroadcastAddresses(); - // Loop through sending N ESPDUs - try - { - System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); - for(int idx = 0; idx < NUMBER_TO_SEND; idx++) - { - // DIS time is a pain in the ass. DIS time units are 2^31-1 units per - // hour, and time is set to DIS time units from the top of the hour. - // This means that if you start sending just before the top of the hour - // the time units can roll over to zero as you are sending. The receivers - // (escpecially homegrown ones) are often not able to detect rollover - // and may start discarding packets as dupes or out of order. We use - // an NPS timestamp here, hundredths of a second since the start of the - // year. The DIS standard for time is often ignored in the wild; I've seen - // people use Unix time (seconds since 1970) and more. Or you can - // just stuff idx into the timestamp field to get something that is monotonically - // increasing. - - // Note that timestamp is used to detect duplicate and out of order packets. - // That means if you DON'T change the timestamp, many implementations will simply - // discard subsequent packets that have an identical timestamp. Also, if they - // receive a PDU with an timestamp lower than the last one they received, they - // may discard it as an earlier, out-of-order PDU. So it is a good idea to - // update the timestamp on ALL packets sent. - - - // An alterative approach: actually follow the standard. It's a crazy concept, - // but it might just work. - int ts = disTime.getDisAbsoluteTimestamp(); - espdu.setTimestamp(ts); - - // Set the position of the entity in the world. DIS uses a cartesian - // coordinate system with the origin at the center of the earth, the x - // axis out at the equator and prime meridian, y out at the equator and - // 90 deg east, and z up and out the north pole. To place an object on - // the earth's surface you also need a model for the shape of the earth - // (it's not a sphere.) All the fancy math necessary to do this is in - // the SEDRIS SRM package. There are also some one-off formulas for - // doing conversions from, for example, lat/lon/altitude to DIS coordinates. - // Here we use those one-off formulas. - - // Modify the position of the object. This will send the object a little - // due east by adding some to the longitude every iteration. Since we - // are on the Pacific coast, this sends the object east. Assume we are - // at zero altitude. In other worlds you'd use DTED to determine the - // local ground altitude at that lat/lon, or you'd just use ground clamping. - // The x and y values will change, but the z value should not. - - //lon = lon + (double)((double)idx / 100000.0); - //System.out.println("lla=" + lat + "," + lon + ", 0.0"); - - double direction = Math.pow((double)(-1.0), (double)(idx)); - lon = lon + (direction * 0.00006); - System.out.println(lon); - - double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 1.0); - Vector3Double location = espdu.getEntityLocation(); - location.setX(disCoordinates[0]); - location.setY(disCoordinates[1]); - location.setZ(disCoordinates[2]); - System.out.println("lat, lon:" + lat + ", " + lon); - System.out.println("DIS coord:" + disCoordinates[0] + ", " + disCoordinates[1] + ", " + disCoordinates[2]); - - // Optionally, we can do some rotation of the entity - /* - Orientation orientation = espdu.getEntityOrientation(); - float psi = orientation.getPsi(); - psi = psi + idx; - orientation.setPsi(psi); - orientation.setTheta((float)(orientation.getTheta() + idx /2.0)); - */ - - // You can set other ESPDU values here, such as the velocity, acceleration, - // and so on. - - // Marshal out the espdu object to a byte array, then send a datagram - // packet with that data in it. - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - espdu.marshal(dos); - - FirePdu fire = new FirePdu(); - byte[] fireArray = fire.marshal(); - - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - - bcastAddresses = getBroadcastAddresses(); - Iterator it = bcastAddresses.iterator(); - while(it.hasNext()) - { - InetAddress bcast = (InetAddress)it.next(); - System.out.println("Sending bcast to " + bcast); - DatagramPacket packet = new DatagramPacket(data, data.length, bcast, 3000); - socket.send(packet); - packet = new DatagramPacket(fireArray, fireArray.length, bcast, 3000); - //socket.send(packet); - } - - // Send every 1 sec. Otherwise this will be all over in a fraction of a second. - Thread.sleep(3000); - - location = espdu.getEntityLocation(); - - System.out.println("Espdu #" + idx + " EID=[" + eid.getSite() + "," + eid.getApplication() + "," + eid.getEntity() + "]"); - System.out.println(" DIS coordinates location=[" + location.getX() + "," + location.getY() + "," + location.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); -// System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - - } - } - catch(Exception e) - { - System.out.println(e); - } - -} - - /** - * A number of sites get all snippy about using 255.255.255.255 for a bcast - * address; it trips their security software and they kick you off their - * network. (Comcast, NPS.) This determines the bcast address for all - * connected interfaces, based on the IP and subnet mask. If you have - * a dual-homed host it will return a bcast address for both. If you have - * some VMs running on your host this will pick up the addresses for those - * as well--eg running VMWare on your laptop with a local IP this will - * also pick up a 192.168 address assigned to the VM by the host OS. - * - * @return set of all bcast addresses - */ - public static Set<InetAddress> getBroadcastAddresses() - { - Set<InetAddress> bcastAddresses = new HashSet<InetAddress>(); - Enumeration interfaces; - - try - { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while(interfaces.hasMoreElements()) - { - NetworkInterface anInterface = (NetworkInterface)interfaces.nextElement(); - - if(anInterface.isUp()) - { - Iterator it = anInterface.getInterfaceAddresses().iterator(); - while(it.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress)it.next(); - if((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - continue; - - //System.out.println("Getting bcast address for " + anAddress); - InetAddress abcast = anAddress.getBroadcast(); - if(abcast != null) - bcastAddresses.add(abcast); - } - } - } - - } - catch(Exception e) - { - e.printStackTrace(); - System.out.println(e); - } - - return bcastAddresses; - } - -} diff --git a/projects/Assignments/homework3/Tackett_Assignment3_README.html b/projects/Assignments/homework3/Tackett_Assignment3_README.html new file mode 100644 index 0000000000000000000000000000000000000000..466feff569a72d4a83bbad9b443a6054fa3d69a9 --- /dev/null +++ b/projects/Assignments/homework3/Tackett_Assignment3_README.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Tackett_Assignment3_README</title> +<style type="text/css">/*...*/</style> +</head> +<body> +<h2>Homework Assignment 3 Checklist</h2> +<ol> + <li><p>[x] Add X3D-Edit as Netbeans Plugin from https://savage.nps.edu/X3D-Edit/#Downloads</p></li> + <li><p>[x] Optional: checkout Open-DIS-Java library source from https://github.com/open-dis/open-dis-java</p></li> + <li><p>[x] Otherwise just inspect files of interest from <a href="https://github.com/open-dis/open-dis-java/tree/master/src/main/java/edu/nps/moves/examples">edu.nps.moves.examples</a></p></li> + <li><p>[x] Copy README.md and create YournameREADME.md documentation file...</p></li> + <li><p>[x] Plan a track of interest, described in YournameREADME.md documentation file...</p> + <pre><code>Track of interest is a sample from a run route I did recently. +</code></pre></li> + <li><p>[x] Copy, then Refactor/Rename example file OpenDisEspduSender.java or OpenDisPduSender.java as YourNameSomething.java</p></li> + <li><p>[x] Modify your example file to produce track PDUs (and be cool)</p></li> + <li><p>[x] Generate PDUs...</p></li> + <li><p>[x] Test PDU reading using Wireshark...</p> + <pre><code>IP address for my machine is 172.20.148.166 +</code></pre></li> + <li><p>[x] Record PDU file using X3D-Edit...</p></li> + <li><p>[x] Playback PDU file using X3D-Edit...</p></li> +</ol> +</body> +</html> \ No newline at end of file diff --git a/projects/Assignments/homework3/Tackett_Assignment3_README.md b/projects/Assignments/homework3/Tackett_Assignment3_README.md new file mode 100644 index 0000000000000000000000000000000000000000..ec5cbee9d81ee3b426d62ab3014fa17ff92a4a9f --- /dev/null +++ b/projects/Assignments/homework3/Tackett_Assignment3_README.md @@ -0,0 +1,28 @@ +## Homework Assignment 3 Checklist + +1. [x] Add X3D-Edit as Netbeans Plugin from https://savage.nps.edu/X3D-Edit/#Downloads + +1. [x] Optional: checkout Open-DIS-Java library source from https://github.com/open-dis/open-dis-java + +1. [x] Otherwise just inspect files of interest from + [edu.nps.moves.examples](https://github.com/open-dis/open-dis-java/tree/master/src/main/java/edu/nps/moves/examples) + +1. [x] Copy README.md and create YournameREADME.md documentation file... + +1. [x] Plan a track of interest, described in YournameREADME.md documentation file... + + Track of interest is a sample from a run route I did recently. + +1. [x] Copy, then Refactor/Rename example file OpenDisEspduSender.java or OpenDisPduSender.java as YourNameSomething.java + +1. [x] Modify your example file to produce track PDUs (and be cool) + +1. [x] Generate PDUs... + +1. [x] Test PDU reading using Wireshark... + + IP address for my machine is 172.20.148.166 + +1. [x] Record PDU file using X3D-Edit... + +1. [x] Playback PDU file using X3D-Edit... diff --git a/projects/MulticastExample/MulticastReceiver/build/classes/multicastreceiver/MulticastReceiver.class b/projects/MulticastExample/MulticastReceiver/build/classes/multicastreceiver/MulticastReceiver.class deleted file mode 100644 index e1a915237414dc52b65fccb0c8215ee80688cf34..0000000000000000000000000000000000000000 Binary files a/projects/MulticastExample/MulticastReceiver/build/classes/multicastreceiver/MulticastReceiver.class and /dev/null differ