No matter what platform, writing network servers that support high concurrency often results in I/O bottlenecks. Currently, the most efficient method is to use the asynchronous I/O model. The Linux platform provides epoll, windows provides the I/O completion port (iocp ).
Windows has provided iocp support since Winsock2. You can use C ++ to directly call the API. net C # development, in. net framework2.0 was introduced. In version 2.0, the most efficient network server is implemented through some columns of asynchronous socket beginxxx and endxxx. The underlying layer is based on iocp.
When.. NET Framework upgraded to 2.0 SP1 ,. net socket provides a more efficient column xxxasync method, which improves the performance of the underlying iocp ,. after the Net Framework was upgraded to 3.5, it became more mature and stable, and Microsoft began to vigorously promote it.
In practical applications, it is proved that C #'s high-performance server based on. NET iocp can support more than 10000 TCP persistent connections. However, pay attention to the following issues during implementation:
1. It is recommended that socketasynceventargs and buffer be allocated in advance and reuse can be recycled.
2. It is recommended that the send and receive Of a socket correspond to a socketasynceventargs respectively, because when a socketasynceventargs is suspended by the receiveasync call, an exception occurs when sendasync is called. Do not call socketasynceventargs again when an asynchronous operation is suspended.
References:
Http://msdn.microsoft.com/zh-cn/magazine/cc163356.aspx
Http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socketasynceventargs.aspx