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);
while(true)
{
p = new DatagramPacket(buf,2);
dg.receive(p);
buf = p.getData();
nvia = buf[0];
if ((nvia <= nvies) && (nvia>0))
vies[nvia-1] = buf[1];
// Mostro l'estat de les vies
System.out.println("\n\n\n");
System.out.println("Estat de les vies");
System.out.println("-----------------");
for (nvia=1; nvia<=nvies; nvia++)
System.out.println("Via " + nvia + ":" + vies[nvia-1]);
}
No buffer space available (maximum connections reached?): Cannot bind
The server seems to enter to an infinite looping without waiting for data to arrive.