问题
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