static void Main(string[] args) { var client = new ReactiveClient("localhost", 41337); var protocol = new ProtobufChannel <Person>(client); protocol.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(person => { if (person != null) { Console.WriteLine("Person {0} {1} received", person.FirstName, person.LastName); } }); client.ConnectAsync().Wait(); var p1 = new Person() { FirstName = "Fritz", LastName = "Phantom" }; var p2 = new Person() { FirstName = "Tom", LastName = "Turbo" }; protocol.SendAsync(p1); protocol.SendAsync(p2); var m1 = new Manager() { FirstName = "U.N.", LastName = "Owen", Salary = 10000 }; protocol.SendAsync(m1); Console.ReadLine(); }
static void Main(string[] args) { var server = new ReactiveListener(41337); server.Connections.Subscribe(socket => { Console.WriteLine("New socket connected {0}", socket.GetHashCode()); var protocol = new ProtobufChannel <Person>(socket); protocol.Receiver.Subscribe(person => { if (person != null) { Console.WriteLine("Person {0} {1} connected", person.FirstName, person.LastName); } }); }); server.Start(); Console.WriteLine("Press Enter to exit"); Console.ReadLine(); }
private static void MainAction() { var exit = new AutoResetEvent(false); var rxClient = new ReactiveClient(Settings.Default.WolRxServerHost, Settings.Default.WolRxServerPort); rxClient.Disconnected += (sender, eventArgs) => { Log.Info("Disconnected from server, reconnecting..."); Task.Factory.StartNew(MainAction); exit.Set(); }; var channel = new ProtobufChannel<MagicPacket>(rxClient); channel.Receiver.SubscribeOn(TaskPoolScheduler.Default).Subscribe(message => { try { Log.InfoFormat("Received message: {0}", message.GetType()); if (!_localBroadcastAddresses.Contains(IPAddress.Parse(message.BroadcastAddress))) return; Log.InfoFormat("Received WakeOnLan-Command for network {0}", message.BroadcastAddress); Log.InfoFormat("Sending magic packet to {0}", message.MacAddress); WolHelper.WakeDestination(message.MacAddress); Log.Info("Magic packet sent"); } catch (Exception ex) { Log.ErrorFormat("Couldn't send magic packet: {0}", ex); } }); try { rxClient.ConnectAsync().Wait(); Log.Info("Connection established, listening for incoming requests"); } catch (Exception) { Log.ErrorFormat("Couldn't connect to Rx Server, reconnecting..."); Thread.Sleep(new TimeSpan(0, 0, 5)); Task.Factory.StartNew(MainAction); exit.Set(); } exit.WaitOne(Timeout.Infinite); Log.Info("Exiting main thread"); }