I’m trying to understand multi-threading in TCP so I’m coding a basic telnet text “router”.
using ReadLine() each thread using a TCP listener will wait for input from the telnet client and then respond based on the text which is sent. I have this working with multiple threads and multiple telnet clients.
I want to conditionally send messages to all threads.
For example, if the text sent from any one thread is “Alert!” then I want every thread for connected clients to execute WriteLine("Alert!")
Does this make sense?
My problem is that I don’t know how to make one thread raise an event in another thread.
You need to look at a Event Broker pattern. Basically you would have one object with an event that all your threads subscribe to. It will also have a method that can be called which will invoke the event. It maybe sounds complicated, but its fairly simple.
Example code is here http://msforge.net/blogs/paki/archive/2007/11/20/EventBroker-implementation-in-C_2300_-full-source-code.aspx.