Advantage of using async socket server

后端 未结 1 500
日久生厌
日久生厌 2021-01-28 02:41

In which situration should we use an async socket (either Tcp or Udp) server over sync socket server?

If it\'s in client side, I understand that we used to use async so

相关标签:
1条回答
  • 2021-01-28 03:17

    On the server side, it's important to allow parallel processing of clients. If you're processing a large request for one client, you don't want a second client's connect request to time out. This does not mean that you have to use asynchronous methods though. You could easily create a separate thread for each connected client, and accept new clients in the main thread, all synchronously (and for Udp you could use queue the processing of each message in a thread from the ThreadPool).

    The asynchronous socket methods already take care of the parallel-ness though (also by using separate threads), so it's a good technique to keep your server running smoothly.

    0 讨论(0)
提交回复
热议问题