Exemple #1
0
        public TcpServer(TcpServerConfig config)
        {
            this.config = config;

            ReceiveAsync <Bind>(async m =>
            {
                try
                {
                    var bootstrap = new ServerBootstrap();
                    bootstrap
                    // TODO configure to use seperate event loop groups
                    .Group(new MultithreadEventLoopGroup())
                    .Channel <TcpServerSocketChannel>()
                    // TODO configure socket options
                    .Option(ChannelOption.SoBacklog, 100)
                    .Option(ChannelOption.SoRcvbuf, 1024 * 16)
                    .Option(ChannelOption.SoSndbuf, 1024 * 16)
                    // TODO configure logging
                    //.Handler(new LoggingHandler("ping-pong-server"))
                    .ChildHandler(new ChannelInitializer(Context.System, Self));

                    // TODO Any threading risk here?
                    channel = await bootstrap.BindAsync(m.LocalAddress);
                    monitor = Sender;

                    Sender.Tell(new Bound(m.LocalAddress));

                    Become(Bound);
                }
                catch (Exception)
                {
                    // TODO Handler exceptions
                    channel = null;
                    monitor = null;
                }
            });
        }
Exemple #2
0
 public static Props Props(TcpServerConfig config)
 {
     return(Akka.Actor.Props.Create(() => new TcpServer(config)));
 }