Advantage of using async socket server

我只是一个虾纸丫 提交于 2021-02-17 06:15:54

问题


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 that it doesn't block the UI thread.. but I'm not sure why we need to use async on server side..


回答1:


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.



来源:https://stackoverflow.com/questions/8098918/advantage-of-using-async-socket-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!