I've set up a selector in the fashion stated in the tutorial though with non-blocking sockets. Occasionally, the receiving TCP socket will return "not ready" and then simply drop the packet.
It tries to read the socket twice and returns "Not ready" both times, and then it just stops trying so the packet is never received. The next packet may arrive properly as this only happens rarely.
What should I do when a TCP socket returns "not ready"? Should I put it in a special buffer that tries to read it again each iteration until it succeeds? What then if it doesn't succeed before another message arrives and is successfully received by the selector algorithm?