4 |
|
|
5 |
|
public class UDPReaderThread extends Thread{ |
6 |
|
|
7 |
< |
public UDPReaderThread(DatagramPacket packet){ |
8 |
< |
try { |
9 |
< |
xml = new String(packet.getData()); |
10 |
< |
} |
11 |
< |
catch (Exception e) { |
12 |
< |
System.out.println("An exception occured while attempting to return an XMLPacket!"); |
13 |
< |
e.printStackTrace(); |
14 |
< |
} |
7 |
> |
public UDPReaderThread(){ |
8 |
> |
// no-args constructor. |
9 |
|
} |
10 |
|
|
11 |
+ |
public void run(DatagramPacket packet){ |
12 |
+ |
rawPacket = packet.getData(); |
13 |
+ |
start(); |
14 |
+ |
} |
15 |
+ |
|
16 |
+ |
public void run(String xml){ |
17 |
+ |
rawPacket = xml.getBytes(); |
18 |
+ |
start(); |
19 |
+ |
} |
20 |
+ |
|
21 |
|
public void run(){ |
22 |
|
|
23 |
< |
System.out.println("UDPReaderThread - Received the following raw stuff: "+xml); |
24 |
< |
|
23 |
> |
// Get a string without any null characters in it. |
24 |
> |
String xml = new String(rawPacket); |
25 |
> |
xml = xml.substring(0, xml.indexOf(0)); |
26 |
> |
|
27 |
> |
// USe my XMLPacketMaker to make an XMLPacket object. |
28 |
|
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
29 |
|
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
30 |
|
|
35 |
|
System.out.println("UDPReaderThread - An XML Packet was read sucessfully: -"); |
36 |
|
packet.printAll(); |
37 |
|
// Now do something with this XMLPacket!!! |
38 |
< |
// .... |
38 |
> |
// .... but what? ;-) |
39 |
> |
|
40 |
|
} |
41 |
|
|
42 |
< |
String xml; |
42 |
> |
byte[] rawPacket; |
43 |
|
} |