1 |
pjm2 |
1.1 |
import java.io.*; |
2 |
|
|
import java.net.*; |
3 |
|
|
import java.util.*; |
4 |
|
|
|
5 |
|
|
// Class used to send arbitrary crap to the XMLReader |
6 |
|
|
|
7 |
|
|
public class XMLSender { |
8 |
|
|
public static void main(String[] args) throws IOException { |
9 |
|
|
|
10 |
pjm2 |
1.2 |
if (args.length != 2) { |
11 |
|
|
System.out.println("Usage: java XMLSender <hostname> <filename.xml>"); |
12 |
pjm2 |
1.4 |
System.exit(0); |
13 |
pjm2 |
1.1 |
} |
14 |
|
|
|
15 |
pjm2 |
1.2 |
int port = 4589; |
16 |
|
|
|
17 |
pjm2 |
1.1 |
// stuff to send |
18 |
pjm2 |
1.2 |
BufferedReader br = new BufferedReader(new FileReader(args[1])); |
19 |
|
|
String xml = ""; |
20 |
|
|
String line = br.readLine(); |
21 |
|
|
while (line != null){ |
22 |
pjm2 |
1.3 |
xml += line; |
23 |
pjm2 |
1.2 |
line = br.readLine(); |
24 |
|
|
} |
25 |
pjm2 |
1.1 |
|
26 |
|
|
// get a datagram socket |
27 |
|
|
DatagramSocket socket = new DatagramSocket(); |
28 |
|
|
|
29 |
|
|
// send request |
30 |
pjm2 |
1.2 |
byte[] buf = xml.getBytes(); |
31 |
pjm2 |
1.1 |
InetAddress address = InetAddress.getByName(args[0]); |
32 |
pjm2 |
1.2 |
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port); |
33 |
pjm2 |
1.1 |
socket.send(packet); |
34 |
|
|
|
35 |
|
|
String dataOut = new String(packet.getData()); |
36 |
pjm2 |
1.2 |
System.out.println("Sending the following: " + dataOut); |
37 |
pjm2 |
1.1 |
|
38 |
|
|
socket.close(); |
39 |
|
|
} |
40 |
|
|
} |