Skip to content
Snippets Groups Projects
Commit c9667b04 authored by Justin Snell's avatar Justin Snell
Browse files

Merge origin/master

parents ffe39583 826b8e8b
No related branches found
No related tags found
No related merge requests found
//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");
}
}
}
//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
......@@ -15,7 +15,7 @@ import edu.nps.moves.disutil.DisTime;
*/
public class Tackett_Assignment3_OpenDisEspduSender
{
public static final int NUMBER_TO_SEND = 5000;
public static final int NUMBER_TO_SEND = 10;
public enum NetworkMode{UNICAST, MULTICAST, BROADCAST};
......@@ -25,6 +25,8 @@ public class Tackett_Assignment3_OpenDisEspduSender
/** Default port we send on */
public static final int DIS_DESTINATION_PORT = 3000;
private static final ArrayList <Float[]> track_coordinates = new ArrayList<>();
/** 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 multicast.
......@@ -42,9 +44,9 @@ public static void main(String args[])
DisTime disTime = DisTime.getInstance(); // TODO explain
int alternator = -1;
// ICBM coordinates for my office
double lat = 36.595517;
double lon = -121.877000;
// Lat/Lon coordinates
// double lat = 36.616366;
// double lon = -121.913065;
// Default settings. These are used if no system properties are set.
// If system properties are passed in, these are over ridden.
......@@ -149,9 +151,51 @@ public static void main(String args[])
// Loop through sending N ESPDUs
try
{
System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString());
Float[] TrackCoor1 = new Float [2];
TrackCoor1[0] = 36.585657f;
TrackCoor1[1] = -121.879920f;
track_coordinates.add(TrackCoor1);
Float[] TrackCoor2 = new Float [2];
TrackCoor2[0] = 36.584853f;
TrackCoor2[1] = -121.880024f;
track_coordinates.add(TrackCoor2);
Float[] TrackCoor3 = new Float [2];
TrackCoor3[0] = 36.583500f;
TrackCoor3[1] = -121.879615f;
track_coordinates.add(TrackCoor3);
Float[] TrackCoor4 = new Float [2];
TrackCoor4[0] = 36.586307f;
TrackCoor4[1] = -121.874582f;
track_coordinates.add(TrackCoor4);
Float[] TrackCoor5 = new Float [2];
TrackCoor5[0] = 36.588670f;
TrackCoor5[1] = -121.877928f;
track_coordinates.add(TrackCoor5);
Float[] TrackCoor6 = new Float [2];
TrackCoor6[0] = 36.591124f;
TrackCoor6[1] = -121.880074f;
track_coordinates.add(TrackCoor6);
Float[] TrackCoor7 = new Float [2];
TrackCoor7[0] = 36.592827f;
TrackCoor7[1] = -121.877149f;
track_coordinates.add(TrackCoor7);
Float[] TrackCoor8 = new Float [2];
TrackCoor8[0] = 36.594051f;
TrackCoor8[1] = -121.877452f;
track_coordinates.add(TrackCoor8);
Float[] TrackCoor9 = new Float [2];
TrackCoor9[0] = 36.594245f;
TrackCoor9[1] = -121.876477f;
track_coordinates.add(TrackCoor9);
Float[] TrackCoor10 = new Float [2];
TrackCoor10[0] = 36.595230f;
TrackCoor10[1] = -121.877537f;
track_coordinates.add(TrackCoor10);
//System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString());
for(int idx = 0; idx < NUMBER_TO_SEND; idx++)
{
System.out.println("Sending espdu packet" + idx + " to " + destinationIp.toString());
// 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
......@@ -197,9 +241,12 @@ public static void main(String args[])
//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 direction = Math.pow((double)(-1.0), (double)(idx));
// lon = lon + (direction * 0.00006);
// System.out.println(lon);
Float lat = track_coordinates.get(idx)[0];
Float lon = track_coordinates.get(idx)[1];
double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 1.0);
Vector3Double location = espdu.getEntityLocation();
......@@ -243,8 +290,8 @@ public static void main(String args[])
DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, 3000);
socket.send(packet);
// TODO experiment with these! 8)
packet = new DatagramPacket(fireArray, fireArray.length, broadcast, 3000); // alternate
socket.send(packet);
// packet = new DatagramPacket(fireArray, fireArray.length, broadcast, 3000); // alternate
// socket.send(packet);
}
// Send every 1 sec. Otherwise this will be all over in a fraction of a second.
......
......@@ -7,18 +7,22 @@
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. [ ] Copy README.md and create YournameREADME.md documentation file...
1. [x] Copy README.md and create YournameREADME.md documentation file...
1. [ ] Plan a track of interest, described in YournameREADME.md documentation file...
1. [x] Plan a track of interest, described in YournameREADME.md documentation file...
1. [ ] Copy, then Refactor/Rename example file OpenDisEspduSender.java or OpenDisPduSender.java as YourNameSomething.java
Track of interest is a sample from a run route I did recently.
1. [ ] Modify your example file to produce track PDUs (and be cool)
1. [x] Copy, then Refactor/Rename example file OpenDisEspduSender.java or OpenDisPduSender.java as YourNameSomething.java
1. [ ] Generate PDUs...
1. [x] Modify your example file to produce track PDUs (and be cool)
1. [ ] Test PDU reading using Wireshark...
1. [x] Generate PDUs...
1. [ ] Record PDU file using X3D-Edit...
1. [x] Test PDU reading using Wireshark...
1. [ ] Playback PDU file using X3D-Edit...
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...
File added
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