| 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 |
if (args.length != 1) { |
| 11 |
System.out.println("Usage: java QuoteClient <hostname>"); |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
// stuff to send |
| 16 |
String text = new String("This is my message - hello!"); |
| 17 |
|
| 18 |
// get a datagram socket |
| 19 |
DatagramSocket socket = new DatagramSocket(); |
| 20 |
|
| 21 |
// send request |
| 22 |
byte[] buf = text.getBytes(); |
| 23 |
InetAddress address = InetAddress.getByName(args[0]); |
| 24 |
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4589); |
| 25 |
socket.send(packet); |
| 26 |
|
| 27 |
String dataOut = new String(packet.getData()); |
| 28 |
System.out.println("Sending: " + dataOut); |
| 29 |
|
| 30 |
socket.close(); |
| 31 |
} |
| 32 |
} |