Sockets...sending data synchronously

Just a question…if i have some method processing an incoming request through wifi…can another thread be sending data? Do i need to use semaphore or lock so 2 things are not done at once?

If there is a read pending on a socket you can still do a send.

if two or more threads could be doing a send I would lock on the socket object before the send.

thanks…i think i need to introduce a lock as i have 2 thread that could be send data and i would not know when they are being done at the same time.

Do you suggest any method for locking?

appreciate your assistance!

Does this locking also apply if you have 2 or more sockets?

I have an application that has a SCADA socket and an HTTP socket. They are used in different threads.

Do I have to do the locking if both sockets are trying to send at the same time?

So far there has not been any issues with the code but just curious if I am doing it right?

@ Dave McLaughlin - yes. no need to restrict sending to one socket at a time.

@ anthonys - I suggest the following:


lock(socket)
{
     socket.Send ();
}

thanks Mike…thats what i have done :slight_smile:

From your comment below…you suggesting that this is not needed for sending?

I was saying you can have two threads, each with its own socket, sending at the same time without locking.