0

I'm trying to have a TCP-Client that listens on a socket but without being blocked by it. meaning - if something is waiting, read it. if not, do something else and come back and check later. I couldn't find any reference to this question.

The best thing, obviously would be to have a "peek" ability the client knows if something is waiting, and how many bytes. I guess this capability is not implemented in TCP, but if there anything that might help me with that?

Yaniv G
  • 307
  • 4
  • 11
  • 2
    Yes, and in fact you already called it by its name: non-blocking sockets. You should find a complete discussion of them, and how to use them, in one of several good books on network programming. – Sam Varshavchik Aug 29 '22 at 18:11
  • 1
    Many times it is far easier to just spin off a separate thread for each connection and use blocking sockets. Also, I don't know your use case, but a library like Poco can make network programming a lot easier. – Tim Roberts Aug 29 '22 at 18:12

0 Answers0