I have wrote software that do that b4 in both java and C#.
For java, socket is not thread safe. When 1 thread tries to read from a
socket ( in block mode ), while the oother thread
tries to write to it, sometimes it will coz error. ( For UDP, did not try
for TCP )
For C#, according to the MSDN doc, it is not meant to be thread safe,
however,
so far i have not encounter any error. ( For TCP, did not try for UDP )
Conclusion I got is, no, socket is not thread safe.
But for C#, since i have not encounter any problem, I took the risk.
>I wrote:
>
[quoted text clipped - 10 lines]
> *cross-posting to the more populated C# language group, in hope of a
> response from there*
Cool Guy - 24 May 2005 14:57 GMT
> But for C#, since i have not encounter any problem, I took the risk.
Thanks for the reply. I'll have to wait on a definite answer on this
before I start this project, though.
Vince P - 24 May 2005 20:24 GMT
This is really intersting,.. I too am writing an IRC Client in C#.
I'm pretty much finished but came to the group here because i get periodic
blocking in the UI thread and I came to find out what sort of threading
issues i might be having.
So i'm going to make sure my socket threads are being marshed properly.
vince
vincepac
at
hotmail
dot
com
>> But for C#, since i have not encounter any problem, I took the risk.
>
> Thanks for the reply. I'll have to wait on a definite answer on this
> before I start this project, though.
Markus Stoeger - 24 May 2005 20:52 GMT
>> But for C#, since i have not encounter any problem, I took the risk.
>
> Thanks for the reply. I'll have to wait on a definite answer on this
> before I start this project, though.
by far not a definite answer, but thats what I do:
two threads, one for sending, one for receiving. both use sock.Poll(...) to
wait until they can read or write. once Poll returns true I use lock() to
lock the socket and call the send/receive functions inside the lock. this
way I can be sure that the send/receive functions 1) do not block and 2) do
not get called at the same time.
I just hope that Poll is thread safe (MSDN docs say it's not guaranteed to
be.. like pretty much everything in .net). So far it seems to work without
problems.
Max
Cool Guy - 24 May 2005 23:15 GMT
> two threads, one for sending, one for receiving. both use sock.Poll(...) to
> wait until they can read or write.
In my case, I'm gonna do this without using Socket.Poll, since I'm gonna be
passing Streams to the reading/writing methods (mainly in order to make
them easier to unit test).
I'm crossing my fingers!
Thanks, all.
Feroze [msft] - 25 May 2005 01:05 GMT
Yes, you should be able to have a read and write operation outstanding on
the socket at the same time.

Signature
feroze
-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.
See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
>I have wrote software that do that b4 in both java and C#.
>
[quoted text clipped - 24 lines]
>> *cross-posting to the more populated C# language group, in hope of a
>> response from there*