1 |
pjm2 |
1.1 |
import java.io.*; |
2 |
|
|
import java.net.*; |
3 |
|
|
import java.util.*; |
4 |
|
|
|
5 |
|
|
public class UDPReaderThread extends Thread{ |
6 |
|
|
|
7 |
pjm2 |
1.5 |
public UDPReaderThread(){ |
8 |
|
|
// no-args constructor. |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
public void run(DatagramPacket packet){ |
12 |
|
|
rawPacket = packet.getData(); |
13 |
pjm2 |
1.6 |
start(); |
14 |
pjm2 |
1.1 |
} |
15 |
|
|
|
16 |
pjm2 |
1.7 |
public void run(String xml){ |
17 |
|
|
rawPacket = xml.getBytes(); |
18 |
|
|
start(); |
19 |
|
|
} |
20 |
|
|
|
21 |
pjm2 |
1.1 |
public void run(){ |
22 |
pjm2 |
1.2 |
|
23 |
pjm2 |
1.4 |
// Get a string without any null characters in it. |
24 |
pjm2 |
1.3 |
String xml = new String(rawPacket); |
25 |
|
|
xml = xml.substring(0, xml.indexOf(0)); |
26 |
|
|
|
27 |
pjm2 |
1.4 |
// USe my XMLPacketMaker to make an XMLPacket object. |
28 |
pjm2 |
1.1 |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
29 |
|
|
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
30 |
pjm2 |
1.2 |
|
31 |
|
|
if (packet == null){ |
32 |
|
|
System.out.println("UDPReaderThread - A null XMLPacket was returned, I think I'll ignore it!"); |
33 |
|
|
return; |
34 |
|
|
} |
35 |
|
|
System.out.println("UDPReaderThread - An XML Packet was read sucessfully: -"); |
36 |
|
|
packet.printAll(); |
37 |
|
|
// Now do something with this XMLPacket!!! |
38 |
pjm2 |
1.4 |
// .... but what? ;-) |
39 |
pjm2 |
1.5 |
|
40 |
pjm2 |
1.1 |
} |
41 |
|
|
|
42 |
pjm2 |
1.3 |
byte[] rawPacket; |
43 |
pjm2 |
1.1 |
} |