sockets: receive and transmit in one time ?

  • Thread starter Thread starter user
  • Start date Start date
U

user

Hello
I have a thread1 in which i am in infinite loop reading data from
socket. But sometimes i want to transmit data using that socket (thread2
decides about it).
Can i simply from thread2 call:
networkStream.Write();
where networkStream is associated with socket from thread1.
That socket is in that moment waiting on networkStream.Read() in thread1.
Will it work ?
How should i solve this problem ?


Thanx
 
Here is a post from Rhett Gong as msft on the subject of sharing sockets.
From all I gathered on the subject, read on one thread and send on other is
fine. I could not find any explicit blessing on the topic however and the
winsock books say it probably is ok but should be syncronized to be sure. I
would test anyway with your app.
=== Here is the post : =============
Hi William,
I have clarified this with a member from our software develop team.

In general one should consider synchronization when concurrently using a
class that is not thread safe.

However for some of the user scenarios the UdpClient class can be used
without explicit synchronization.
Such as one thread could be doing read and other thread could be doing
send, fine.
Concurrent Reads are not supported on UdpClient though they are supported
on the socket level.
Concurrent Sends are supported as far as the remote address does not change.

I hope this helps.

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support
 
Back
Top