Here is the problem, I have below scenario coded.
- A TCP Listener running in thread A connecting to a Client 1
- A Second TCP Listener running in thread B Connecting to multiple clients each in a different thread. By this I mean as soon as a client is accepted in thread B, A different thread is created for further processing of the client where it waits to get data from "TCP Listener B" in a while loop
What I want to do and where I'm facing problem is,
I want to pass data recieved from Thread 1 by the Client 1 to clients in thread 2.
What I believe is happening,
Since I'm in Thread 1 when I get data from Client 1 in Thread 1, when I try sending data to clients in thread 2, I always get connection false.
Is this a threading issue?
How can I overcome it issue?
EDIT
It's a windows form application
Both the TCP Listener run in same application.
I'm maintaining a list of TcpClients that connect to TCP Listener B and when I get some data from thread A, I get the TCP Client from this list that I maintain and try to send the data, but cannot as connection state becomes false.
I've had the same problem, so i used a backgroundworker instead of a thread to handle the Clients. Here is the extracted code from my project:
And in ThreadProc its just handling every client
And to broadcast information i did this
i hope his helps. You can look at the finished project at https://github.com/hrkrx/MontagsmalerVS the examples are from the HostController.cs