LinkedList<DatagramPacket> queue = new LinkedList<DatagramPacket>();
for (int i = 0; i < queue.size(); i++)
{
System.out.println("1: This prints.");
System.out.println("2: This doesn't: " + new String(queue.get(i).getData()));
int start = (new String(queue.get(i).getData())).indexOf("\r\n") + "\r\n".length();
data.concat(new String(queue.get(i).getData()).substring(start));
}
We're trying to take all the data from queue
, the list of packets, and put them all into one string.
But whenever it gets to the 2nd println
(which is the same as the line below it) the program hangs and doesn't do anything.
Without the getData()
the print works. eg.
System.out.printlin("2: This doesn't: " + new String(queue.get(i)));
Also, whenever I add a packet to the queue, I immediately print the last packet in the queue, and that works.
public void addPacket(DatagramPacket additional)
{
queue.add(additional);
System.out.println("1: " + new String(queue.getLast().getData()));
}