Since a socket is full duplexed, meaning you can send and recieve simultaneously. So, is the .NET Socket Send()/Receive() thread-safe? I need to Send() and Receive() in 2 threads.
Generally they are not thread safe since send is not an atomic operation.
Sockets are thread unsafe at the stream level. You have to provide synchronization. The only warranty is that you won't get copies of the exact same bytes in different read invocations no matter concurrency.
3.10 - Is Winsock thread-safe? On modern Windows stacks, yes, it is, within limits. It is safe, for instance, to have one thread calling send() and another thread calling recv() on a single socket.
accept is declared as MT-Safe, according to doc: MT-Safe or Thread-Safe functions are safe to call in the presence of other threads.
Quote from the MSDN docs about the Socket class (under Thread Safety, towards the end of the page):
Instances of this class are thread safe.
So I would suppose the answer is "yes".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With