package mil.navy.nps.testing; /** DatagramSender: Datagram socket sender This just spits out some datagram packets on the given socket (port 8004). It is used only to generate some packets for testing other things. */ import java.io.*; import java.lang.*; import java.net.*; import java.util.*; import mil.navy.nps.dis.*; public class DatagramSender { // Ignore exceptions for now. public static void main(String argv[]) throws UnknownHostException, SocketException, UnknownHostException, IOException { byte outputBuffer[] = new byte[1500]; // buffer to hold datagram data DatagramSocket dgramSocket; // socket to spit it out on DatagramPacket dgramPacket; // one datagram packet InetAddress dgramDest; // destination internet address int datagramSentCount = 0; dgramSocket = new DatagramSocket(8224); // Send on this socket dgramDest = InetAddress.getLocalHost(); // send to this host // Spit out datagram packets every now and then while(true) { outputBuffer[0] = 1; outputBuffer[1] = 2; // just some random data // send to socket 8004 dgramPacket = new DatagramPacket(outputBuffer, outputBuffer.length, dgramDest, 8004); dgramSocket.send(dgramPacket); datagramSentCount++; if(datagramSentCount % 100 == 0) System.out.println("sent " + datagramSentCount + " datagrams"); } } }