Most efficient way to handle a client connection (socket programming)

后端 未结 7 681
走了就别回头了
走了就别回头了 2021-01-18 11:26

For every single tutorials and examples I have seen on the internet for Linux/Unix socket tutorials, the server side code always involves an infinite loop that checks for cl

7条回答
  •  借酒劲吻你
    2021-01-18 11:54

    When you are implementing a server that listens for possibly infinite connections, there is imo no way around some sort of infinite loops. Usually this is not a problem at all, because when your socket is not marked as non-blocking, the call to accept() will block until a new connection arrives. Due to this blocking, no system resources are wasted.

    Other libraries that provide like an event-based system are ultimately implemented in the way described above.

提交回复
热议问题