C
C#17mo ago
qqdev

Async TCP server with many connections

How to create an async TCP server which can handle many connections without creating a dedicated thread for each one? - ReceiveAsync(...) without SocketAsyncEventArgs is blocking (when being awaited) -> ❌ I guess? - ReceiveAsync(...) with SocketAsyncEventArgs is not blocking -> ✅ I guess? - BeginReceive(...) does not block and uses the (async) callback mechanism -> ✅ I guess? Which one to use?
4 Replies
Buddy
Buddy17mo ago
People recommend to use AcceptAsync and ReceiveAsync
qqdev
qqdev17mo ago
Thanks a lot! I just saw that the code in question is using TcpClient Would you still use ReceiveAsync(...) via tcpClient.Client.ReceiveAsync(...) or tcpClient.BeginRead(...)?
Buddy
Buddy17mo ago
Based on previous conversations, Begin methods are methods you should not use anymore. Though they are easier.
qqdev
qqdev17mo ago
Aight, thanks a lot!