I have a UDP socket and I am waiting for requests from clients. Upon request I read a line from a file and send a datagram back with that line as payload. But the socket.receive()
seems only to be blocking for the first request (loop-iteration), subsequent socket.receive()
calls don't block anymore. Is that normal? Why could this be?
String input;
DatagramSocket socket = new DatagramSocket(port);
DatagramPacket answer;
while((input=fileIn.readline()))!=null){
socket.receive(request);
...
//send answer back
byte[] load = input.getBytes();
answer = new DatagramPacket(load, load.length, address, port);
socket.send(answer);
}
socket.close();
The programm already sends all the filedata , so all lines of the file after the 1st request., and therefore jumps over the blocking socket.receive()
.