1 |
pjm2 |
1.1 |
import java.io.*; |
2 |
|
|
import java.net.*; |
3 |
|
|
import java.util.*; |
4 |
|
|
|
5 |
|
|
// Class used to send lots of arbitrary crap to the XMLReader |
6 |
|
|
|
7 |
|
|
public class XMLSender2 { |
8 |
|
|
public static void main(String[] args) throws Exception { |
9 |
|
|
|
10 |
|
|
if (args.length != 1) { |
11 |
|
|
System.out.println("Usage: java XMLSender <hostname>"); |
12 |
|
|
System.exit(0); |
13 |
|
|
} |
14 |
|
|
|
15 |
pjm2 |
1.3 |
System.out.println("Repeatedly sending the same packet to port 4589 ..."); |
16 |
|
|
System.out.println("(*about* 100 per second, with id numbers)"); |
17 |
pjm2 |
1.1 |
|
18 |
pjm2 |
1.3 |
int port = 4589; |
19 |
pjm2 |
1.1 |
|
20 |
|
|
// stuff to send |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
// get a datagram socket |
24 |
|
|
DatagramSocket socket = new DatagramSocket(); |
25 |
|
|
InetAddress address = InetAddress.getByName(args[0]); |
26 |
|
|
|
27 |
|
|
int id = 0; |
28 |
|
|
boolean running = true; |
29 |
|
|
while (running){ |
30 |
|
|
id++; |
31 |
|
|
String xml = "<packet><id>"+id+"</id></packet>"; |
32 |
|
|
byte[] buf = xml.getBytes(); |
33 |
|
|
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port); |
34 |
|
|
// send request repeatedly |
35 |
|
|
socket.send(packet); |
36 |
pjm2 |
1.2 |
Thread.sleep(1); |
37 |
pjm2 |
1.1 |
} |
38 |
|
|
|
39 |
|
|
socket.close(); |
40 |
|
|
} |
41 |
|
|
} |