Main Site Documentation

Sockets...sending data synchronously


#1

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?


#2

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.


#3

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!


#4

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?


#5

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


#6

@ anthonys - I suggest the following:


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


#7

thanks Mike…thats what i have done :slight_smile:

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


#8

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