Writing a highly scalable TCP/IP server in C# 5 with the async/await pattern?

What is the best way to use the new Async methods on Socket, TcpClient or TcpListener to create a scalable server in C#?

There aren't any new async methods on Socket; the methods named *Async on Socket are a special set of APIs to reduce memory usage. TcpClient and TcpListener did get some new async methods.

If you want the best scalability, you're probably best using Stephen Toub's custom awaiters for Socket. If you want the easiest to code, you're probably better off using TcpClient and TcpListener.

Do the new Async methods leverage I/O Completion Ports?

Yes, just like most of the other asynchronous APIs in the BCL. AFAIK, the Stream class is the only one that may possibly not use the IOCP; all other *Begin/*End/*Async methods use the IOCP.

Is rolling your own Socket listener more efficient, or are the TcpListener/TcpClient classes pretty good now?

The classes are pretty good as they are. Stephen Toub has a blog post that is a bit more efficient in terms of memory use.


With .net4.5 you can use async/await keyword to build tcp server. Here is the sample code. async await tcp server

It can accept more than 10K connections. tcp server