public delegate void MyDel(); public class ServerClass : MarshalByRefObject { public event MyDel myEvent; public void StartServer (bool shouldFireEvent) { TcpServerChannel tsc; BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary di = new Hashtable(); di["port"] = 8085; di["bindTo"] = "172.19.35.191"; tsc = new TcpServerChannel(di, provider); ChannelServices.RegisterChannel(tsc, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass), "myURI", WellKnownObjectMode.Singleton); if (shouldFireEvent) { while (true) { myEvent(); Thread.Sleep(1000); } } } }Server GUI-----------------------------
public delegate void MyDel(); public class ServerClass : MarshalByRefObject { public event MyDel myEvent; public void StartServer (bool shouldFireEvent) { TcpServerChannel tsc; BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary di = new Hashtable(); di["port"] = 8085; di["bindTo"] = "172.19.35.191"; tsc = new TcpServerChannel(di, provider); ChannelServices.RegisterChannel(tsc, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass), "myURI", WellKnownObjectMode.Singleton); if (shouldFireEvent) { while (true) { myEvent(); Thread.Sleep(1000); } } } }
class ServerGui { static void Main(string[] args) { ServerClass server = new ServerClass(); server.myEvent += new MyDel(ReceivedEventFromServerHandler); //lets register to event server.StartServer(true); Console.WriteLine("server is running. press enter to quit"); Console.ReadKey(); } static void ReceivedEventFromServerHandler() { Console.WriteLine("I am the server GUI. Got a message from the server"); } }Client-------------- class ClientClass { static void Main(string[] args) { ServerClass server = (ServerClass)Activator.GetObject(typeof(ServerClass), "tcp://172.19.35.191:8085/myURI"); server.myEvent += new MyDel(server_myEvent); //HERE IT CRASHES while (true) { Thread.Sleep(1000); } } static void server_myEvent() { Console.WriteLine("I am the client. Got a message from the server over the network"); } }
class ServerGui { static void Main(string[] args) { ServerClass server = new ServerClass(); server.myEvent += new MyDel(ReceivedEventFromServerHandler); //lets register to event server.StartServer(true); Console.WriteLine("server is running. press enter to quit"); Console.ReadKey(); } static void ReceivedEventFromServerHandler() { Console.WriteLine("I am the server GUI. Got a message from the server"); } }
Client--------------
class ClientClass { static void Main(string[] args) { ServerClass server = (ServerClass)Activator.GetObject(typeof(ServerClass), "tcp://172.19.35.191:8085/myURI"); server.myEvent += new MyDel(server_myEvent); //HERE IT CRASHES while (true) { Thread.Sleep(1000); } } static void server_myEvent() { Console.WriteLine("I am the client. Got a message from the server over the network"); } }