I have an application which sends a DatagramPacket to another by using a DatagramSocket. The sending application has a loop which gets a data from user (2 bytes) and then sends it to the receiving application. The receiving application has a loop which gets data from the DatagramSocket and prints it to console.
First packet is sended ok and showed to console by the receiver. However, after that, when receiver repeats the loop, the instruction dg.receive(p); doesn't seems to keep wainting until new data is received.
This is the code on the receiver:
dg = new DatagramSocket(port);
p = new DatagramPacket(buf,2);
buf = p.getData();
nvia = buf;
if ((nvia <= nvies) && (nvia>0))
vies[nvia-1] = buf;
// Mostro l'estat de les vies
System.out.println("Estat de les vies");
for (nvia=1; nvia<=nvies; nvia++)
System.out.println("Via " + nvia + ":" + vies[nvia-1]);