private static GatewayRef[] StartGateway(ActorSystem system, ChannelType type, int port, int port2)
        {
            var serializer  = PacketSerializer.CreatePacketSerializer();
            var environment = new EntryActorEnvironment();

            // First gateway

            var initiator = new GatewayInitiator
            {
                ListenEndPoint      = new IPEndPoint(IPAddress.Any, port),
                GatewayLogger       = LogManager.GetLogger("Gateway"),
                GatewayInitialized  = a => { environment.Gateway = a.Cast <ActorBoundGatewayRef>(); },
                CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel({ep}"),
                ConnectionSettings  = new TcpConnectionSettings {
                    PacketSerializer = serializer
                },
                PacketSerializer    = serializer,
                CreateInitialActors = (context, connection) => new[]
                {
                    Tuple.Create(context.ActorOf(Props.Create(() => new EntryActor(environment, context.Self.Cast <ActorBoundChannelRef>()))),
                                 new TaggedType[] { typeof(IEntry) },
                                 (ActorBindingFlags)0)
                }
            };

            var gateway = (type == ChannelType.Tcp)
                ? system.ActorOf(Props.Create(() => new TcpGateway(initiator))).Cast <GatewayRef>()
                : system.ActorOf(Props.Create(() => new UdpGateway(initiator))).Cast <GatewayRef>();

            gateway.Start().Wait();

            // Second gateway

            var initiator2 = new GatewayInitiator
            {
                ListenEndPoint      = new IPEndPoint(IPAddress.Any, port2),
                ConnectEndPoint     = new IPEndPoint(IPAddress.Loopback, port2),
                GatewayLogger       = LogManager.GetLogger("Gateway2"),
                TokenRequired       = true,
                GatewayInitialized  = a => { environment.Gateway2nd = a.Cast <ActorBoundGatewayRef>(); },
                CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel2({ep}"),
                ConnectionSettings  = new TcpConnectionSettings {
                    PacketSerializer = serializer
                },
                PacketSerializer = serializer,
            };

            var gateway2 = (type == ChannelType.Tcp)
                ? system.ActorOf(Props.Create(() => new TcpGateway(initiator2))).Cast <GatewayRef>()
                : system.ActorOf(Props.Create(() => new UdpGateway(initiator2))).Cast <GatewayRef>();

            gateway2.Start().Wait();

            return(new[] { gateway, gateway2 });
        }
 public EntryActor(EntryActorEnvironment environment, ActorBoundChannelRef channel)
 {
     _environment = environment;
     _channel     = channel.WithRequestWaiter(this);
 }
 public EntryActor(EntryActorEnvironment environment, ActorBoundChannelRef channel)
 {
     _environment = environment;
     _channel = channel.WithRequestWaiter(this);
 }