package mil.navy.nps.testing; import mil.navy.nps.util.*; // utilities import mil.navy.nps.dis.*; // DIS library import java.net.*; // for some networking things import java.util.*; // for vectors, etc class CollisionMonitor extends Object { // Constants. Change these to reflect the port and/or multicast // address you want to listen to. If you want to listen to a // unicast address, set MULTICAST to false and set the port number // to what you want. The multicast address will be ignored in that // case. static final String MULTICAST_ADDRESS = new String("224.2.244.141"); static final int PORT = 3111; static final boolean MULTICAST = false; // The network monitor and the thread that reads from the wire. BehaviorStreamBufferUDP behaviorStreamBufferUDP; // The network monitor Thread networkReadThread; // the thread the network monitor uses to read from the wire public CollisionMonitor() { // Instantiate an instance of behaviorStreamBufferUDP, either multicast // or unicast, depending on what's set up in the constants section // above. if(MULTICAST) behaviorStreamBufferUDP = new BehaviorStreamBufferUDP(MULTICAST_ADDRESS, PORT); else behaviorStreamBufferUDP = new BehaviorStreamBufferUDP(PORT); // The thread runs the network monitor and begins reading. networkReadThread = new Thread(behaviorStreamBufferUDP); // behaviorStreamBufferUDP.setThread(networkReadThread); networkReadThread.start(); return; } public void writeExample() { int idx; // Loop through several times, sending out a PDU every now and // then. This sends out on a unicast socket. CollisionPdu coll = new CollisionPdu(); // instance of a PDU while(true) { idx=2; coll.setIssuingEntityID(new EntityID((short)idx,(short)idx,(short)idx)); coll.setCollidingEntityID(new EntityID((short)(idx+1),(short)(idx+1),(short)(idx+1))); coll.setEventID(new EventID((short)(idx+2),(short)(idx+2),(short)(idx+2))); coll.setCollisionType(new mil.navy.nps.util.UnsignedByte(19*idx%11)); coll.setLinearVelocity((float) (1.1*idx), (float) (1.1*idx), (float) (1.1*idx)); coll.setMass((float) (1001*idx)); coll.setLocation((float) (10.1*idx), (float) (10.1*idx), (float) (10.1*idx)); behaviorStreamBufferUDP.sendPdu(coll, new String("devo.cs.nps.navy.mil"), 8006); System.out.println("sent PDU number " + idx); // So we don't spit these out at some obscene rate, go to sleep // for n milliseconds between sends. try { Thread.sleep(2000); // go to sleep } catch(InterruptedException interruptedException) { throw new RuntimeException("Exceptional sleep "); } } // end of loop } // end of write example public static void main(String args[]) { // The main operation, just used as an entry point. CollisionMonitor example = new CollisionMonitor(); example.writeExample(); return; } } // end of class CollisionMonitor