Public UDP socket accessed by multiple threads ???

  • Thread starter Thread starter cSharpDotNet
  • Start date Start date
C

cSharpDotNet

I am attempting to create a UDP socket where inbound traffic is handled by one thread and outbound traffic is handled by another thread. The primary problem that I am having is accessing the thread from more than one thread. It also seems the .NET does not support public global socket delcarations. Anyone got any ideas?
 
When you have the socket ref, you can pass it to any method or constructor
(say you have one class for reader and one for writer.) You will not find
(if you do, please let me know) explicit reference saying this is supported
in the winsock 2.0 or .net without syncronization. However, I have asked
this question before and got a reply from MS that one reader and one writer
would be ok. See the other post on this - maybe a 3 days ago.

--
William Stacey, MS MVP

cSharpDotNet said:
I am attempting to create a UDP socket where inbound traffic is handled by
one thread and outbound traffic is handled by another thread. The primary
problem that I am having is accessing the thread from more than one thread.
It also seems the .NET does not support public global socket delcarations.
Anyone got any ideas?Community Website: http://www.dotnetjunkies.com/newsgroups/
 
The problem is that a method used for threading does not allow for parameters to be passed to it. Is there a way around this? I would really like to be listening for UDP in one thread and sending UDP in another.
 
Create a new class. The class will contain the reader thread. You could
also create the writer thread in the class or create another class that
contains the writer thread. Then:
1) Create the socket and get the ref.
2) Create the reader (and writer) class instances, pass in the ref to the
socket during construction of the class.
3) Now the class (or classes) have the ref to the socket. Store that in a
private field of the class.
4) Make a Start() method on the class. This method will start the thread
and use a private method for the start delegate. This method will have
access to the private socket ref. Now you have access to the socket. Other
classes could get access the same way. Does that make sense? hth

--
William Stacey, MVP

cSharpDotNet said:
The problem is that a method used for threading does not allow for
parameters to be passed to it. Is there a way around this? I would really
like to be listening for UDP in one thread and sending UDP in another.Community Website: http://www.dotnetjunkies.com/newsgroups/
 
Back
Top