Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is .NET Socket Send()/Receive() thread-safe?

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.

like image 275
Dagang Avatar asked Jul 28 '10 08:07

Dagang


People also ask

Is socket send thread safe?

Generally they are not thread safe since send is not an atomic operation.

Is Java net socket thread safe?

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.

Is Winsock thread safe?

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.

Is accept thread safe?

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.


1 Answers

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".

like image 145
Fredrik Mörk Avatar answered Oct 19 '22 05:10

Fredrik Mörk