public override async Task Start() { var serializer = PacketSerializer.CreatePacketSerializer(); var name = "UserLoginGateway"; var initiator = new GatewayInitiator { ListenEndPoint = _listenEndPoint, GatewayLogger = LogManager.GetLogger(name), CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel({ep}"), ConnectionSettings = new TcpConnectionSettings { PacketSerializer = serializer }, PacketSerializer = serializer, CreateInitialActors = (context, connection) => new[] { Tuple.Create( context.ActorOf(Props.Create(() => new UserLoginActor(_context, context.Self.Cast <ActorBoundChannelRef>(), GatewayInitiator.GetRemoteEndPoint(connection)))), new TaggedType[] { typeof(IUserLogin) }, ActorBindingFlags.CloseThenStop | ActorBindingFlags.StopThenCloseChannel) } }; _gateway = (_channelType == ChannelType.Tcp) ? _context.System.ActorOf(Props.Create(() => new TcpGateway(initiator)), name).Cast <GatewayRef>() : _context.System.ActorOf(Props.Create(() => new UdpGateway(initiator)), name).Cast <GatewayRef>(); await _gateway.Start(); }
private async Task <GatewayRef> StartListen(ActorSystem system, ChannelType type, int port) { var serializer = PacketSerializer.CreatePacketSerializer(); var name = $"Gateway({type})"; var initiator = new GatewayInitiator { ListenEndPoint = new IPEndPoint(IPAddress.Any, port), GatewayLogger = LogManager.GetLogger(name), CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel({ep}"), ConnectionSettings = new TcpConnectionSettings { PacketSerializer = serializer }, PacketSerializer = serializer, CreateInitialActors = (context, connection) => new[] { Tuple.Create( context.ActorOf(Props.Create(() => new Greeter(context.Self.Cast <ActorBoundChannelRef>(), GatewayInitiator.GetRemoteEndPoint(connection)))), new TaggedType[] { typeof(IGreeter) }, (ActorBindingFlags)0) } }; var gateway = (type == ChannelType.Tcp) ? system.ActorOf(Props.Create(() => new TcpGateway(initiator)), name).Cast <GatewayRef>() : system.ActorOf(Props.Create(() => new UdpGateway(initiator)), name).Cast <GatewayRef>(); await gateway.Start(); return(gateway); }