public Program(IPEndPoint ip, string user = "******") { p = new ProbeActor(ip) { Name = user }; this.WhenAnyValue(t => t.p.Connected) .Subscribe(b => Console.WriteLine($"From VM Connection {ip.Address} {ip.Port} = {b}")); }
public ProbeClientActor(string ip = "10.30.12.13", int port = 8081, string user = "******", ProbeActor _prog = null) { prog = _prog; _server = Context.ActorSelection($"akka.tcp://MyServer@{ip}:{port}/user/ChatServer"); #region Message Processing Receive <ConnectRequest>(cr => { _server.Tell(cr); }); Receive <ConnectResponse>(rsp => { }); Receive <NickResponse>(nrsp => { Console.WriteLine("{0} is now known as {1}", nrsp.OldUsername, nrsp.NewUsername); }); Receive <SayRequest>(sr => { sr.Username = "******"; _server.Tell(sr); }); Receive <SayResponse>(srsp => { //Console.WriteLine("{0}: {1}", srsp.Username, srsp.Text); }); #endregion Receive <Terminated>(t => { prog.Connected = false; //Console.WriteLine("Terminated: " + t.ToString()); Context.Stop(serverRef); Connected = false; Context.System.Terminate(); }); // Listen to Association Error Receive <AssociationErrorEvent>(e => { Console.WriteLine($"Association Error {e.LocalAddress}. Restarting {Connected}"); if (Connected) { (Self as LocalActorRef).Restart(new Exception()); } }); // Listen for Disassociated Receive <DisassociatedEvent>(e => { prog.Connected = false; Console.WriteLine($"Disaccociated Event {e.LocalAddress} {e.RemoteAddress}"); //LocalActorRef localActorRef = Self as LocalActorRef; Context.Unwatch(serverRef); Context.System.EventStream.Unsubscribe <DisassociatedEvent>(Self); Context.System.EventStream.Unsubscribe <AssociationErrorEvent>(Self); Self.GracefulStop(TimeSpan.FromMilliseconds(1)); Context.System.Terminate(); }); // Listen for Association Context.System.EventStream.Subscribe <AssociatedEvent>(Self); Receive <AssociatedEvent>(e => { //Console.WriteLine($"Associated Event {e.LocalAddress} {e.RemoteAddress}"); //Console.WriteLine("Calling OnConnected Function"); Context.System.EventStream.Subscribe <DisassociatedEvent>(Self); Context.System.EventStream.Subscribe <AssociationErrorEvent>(Self); prog.Connected = true; }); // Quarantined Context.System.EventStream.Subscribe <QuarantinedEvent>(Self); Receive <QuarantinedEvent>(q => { //Console.WriteLine($"++++Quarantined {q.Address}"); Context.System.Stop(Self); }); Receive <RemotingLifecycleEvent>(r => { Console.WriteLine($"****RemotingLifecycleEvent: {r}"); }); }