new Thread(new Runnable() {
public void run() {
try {
//fake a discovery server to send back some canned messages.
InetAddress address = InetAddress.getByName("239.255.255.250");
MulticastSocket s = new MulticastSocket(Integer.parseInt(PORT));
s.setBroadcast(true);
s.joinGroup(address);
s.setReceiveBufferSize(64 * 1024);
s.setSoTimeout(5000);
byte[] bytes = new byte[64 * 1024];
DatagramPacket p = new DatagramPacket(bytes, bytes.length, address, Integer.parseInt(PORT));
s.receive(p);
SocketAddress sa = p.getSocketAddress();
String incoming = new String(p.getData(), 0, p.getLength(), "UTF-8");
int idx = incoming.indexOf("MessageID");
idx = incoming.indexOf('>', idx);
incoming = incoming.substring(idx + 1);
idx = incoming.indexOf("</");
incoming = incoming.substring(0, idx);
for (int x = 1; x < 4; x++) {
InputStream ins = WSDiscoveryClientTest.class.getResourceAsStream("msg" + x + ".xml");
String msg = IOUtils.readStringFromStream(ins);
msg = msg.replace("urn:uuid:883d0d53-92aa-4066-9b6f-9eadb1832366",
incoming);
byte out[] = msg.getBytes("UTF-8");
DatagramPacket outp = new DatagramPacket(out, 0, out.length, sa);
s.send(outp);
}
s.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();