| 7 |
|
public class XMLSender { |
| 8 |
|
public static void main(String[] args) throws IOException { |
| 9 |
|
|
| 10 |
< |
if (args.length != 1) { |
| 11 |
< |
System.out.println("Usage: java QuoteClient <hostname>"); |
| 12 |
< |
return; |
| 10 |
> |
if (args.length != 2) { |
| 11 |
> |
System.out.println("Usage: java XMLSender <hostname> <filename.xml>"); |
| 12 |
|
} |
| 13 |
|
|
| 14 |
+ |
int port = 4589; |
| 15 |
+ |
|
| 16 |
|
// stuff to send |
| 17 |
< |
String text = new String("This is my message - hello!"); |
| 17 |
> |
BufferedReader br = new BufferedReader(new FileReader(args[1])); |
| 18 |
> |
String xml = ""; |
| 19 |
> |
String line = br.readLine(); |
| 20 |
> |
while (line != null){ |
| 21 |
> |
xml += line; |
| 22 |
> |
line = br.readLine(); |
| 23 |
> |
} |
| 24 |
|
|
| 25 |
|
// get a datagram socket |
| 26 |
|
DatagramSocket socket = new DatagramSocket(); |
| 27 |
|
|
| 28 |
|
// send request |
| 29 |
< |
byte[] buf = text.getBytes(); |
| 29 |
> |
byte[] buf = xml.getBytes(); |
| 30 |
|
InetAddress address = InetAddress.getByName(args[0]); |
| 31 |
< |
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4589); |
| 31 |
> |
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port); |
| 32 |
|
socket.send(packet); |
| 33 |
|
|
| 34 |
|
String dataOut = new String(packet.getData()); |
| 35 |
< |
System.out.println("Sending: " + dataOut); |
| 35 |
> |
System.out.println("Sending the following: " + dataOut); |
| 36 |
|
|
| 37 |
|
socket.close(); |
| 38 |
|
} |