C
C#2y 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
Buddy2y ago
People recommend to use AcceptAsync and ReceiveAsync
qqdev
qqdevOP2y 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
Buddy2y ago
Based on previous conversations, Begin methods are methods you should not use anymore. Though they are easier.
qqdev
qqdevOP2y ago
Aight, thanks a lot!
Want results from more Discord servers?
Add your server