I would expect if you read UDP. Notice how slowly you process packets using the read
method. You print them to system.out, which is very slow, and not sure how fast you can process data in another thread using the processData
method. This library that I wrote can help you make cross-threaded non-blocking communication if this is the source of your delay. You should also check the size of your base socket buffer. The larger it is, the more space you have to be quick and catch up before the packages start to drop. For TCP, you are likely to get an IOException on the channel if the underlying socket buffer is full. For UDP packets are silently deleted.
To access the base socket buffer size you can do:
final Socket socket = channel.socket(); System.out.println(socket.getReceiveBufferSize()); socket.setReceiveBufferSize(newSize);
Note. AFAIK Linux may require some OS configuration so that you can resize the base buffer. If setReceiveBufferSize
has no effect (read it again to see if it has changed), report it to google. :)
source share