Inheritance: INetNodeConfig
        INetNode CreateNetNode(StatefulServiceContext initParams)
        {
            var logger = new LoggerConfiguration()
                .ConfigureMOUSETypesDestructure()
                .MinimumLevel.Verbose()
                .WriteTo.Seq("http://localhost:5341/")
                .CreateLogger();

            var coreEventsLogger = new SerilogCoreEvents(logger);
            var lidgrenEventsLogger = new SerilogLidgrenEvents(logger);


            var messageSerializer = new ProtobufMessageSerializer(typeof(Message).Assembly, typeof(Say).Assembly);

            var endPoint = initParams
                .CodePackageActivationContext
                .GetEndpoint("ServiceEndPoint");

            var nodeContext = FabricRuntime.GetNodeContext();

            string nodeName = $"{nodeContext.NodeName}:{nodeContext.NodeId}";

            var transport = new LidgrenNetProvider(
                new NetPeerConfiguration("Public")
                {
                    MaximumConnections = 10,
                    AcceptIncomingConnections = true,
                    Port = endPoint.Port,
                    LocalAddress = Dns.GetHostAddresses(nodeContext.IPAddressOrFQDN).First(x => x.AddressFamily == AddressFamily.InterNetwork)
                },
                lidgrenEventsLogger);

            var netConfig = new NetNodeConfig()
            {
                ConnectTimeoutSec = 30,
                SendTimeoutSec = 30
            };

            var bufferPool = new WcfBufferPool();
            
            var node = new NetNode<NetChannel>(nodeName, transport, coreEventsLogger, messageSerializer,
                    config: netConfig,
                    channelFactory: (owner, transportChannel) =>
                        new AsyncProcessingNetChannel(builder => builder
                            .UseFiber(Fiber, config => config
                                .Lock<Say>(LockType.Read)
                                .Lock<JoinRoom>(LockType.Write)
                                .Lock<PeerDisconnected>(LockType.Write))
                            .UseConfigurableDispatcher(config => config
                                .HandleMessageAsync<Say>(OnSay)
                                .HandleMessageAsync<JoinRoom>(OnRoomJoin)
                                .HandleMessageAsync<PeerDisconnected>((msg, o) => OnRoomLeave(o.ReplyChannel))),
                            owner, transportChannel, messageSerializer, coreEventsLogger, netConfig, bufferPool));

            return node;
        }
        static void Main(string[] args)
        {
            //configure serialization
            var messageSerializer = new ProtobufMessageSerializer(typeof(Message).Assembly, typeof(JoinRoom).Assembly);
            
            var logger = new LoggerConfiguration()
                .ConfigureMOUSETypesDestructure()
                .MinimumLevel.Error()
                .WriteTo.ColoredConsole()
                .CreateLogger();
            
            var coreEventLogger = new SerilogCoreEvents(logger);

            //configure network transport provider
            

            Action<ISimpleMessageHandlingConfigBuilder> messageHandlingConfigurator =
                c => c.HandleMessage<RoomEvent>(OnRoomEvent);

            //Console.WriteLine("Connect to");

            Console.WriteLine("Enter how many clients to run simultaneously");
            var clientCount = int.Parse(Console.ReadLine());

            string roomName = Guid.NewGuid().ToString();


            for (int i = 0; i < clientCount; i++)
            {
                var transport = new LidgrenNetProvider(
                    new NetPeerConfiguration("Public")
                    {
                        ConnectionTimeout = 30
                    },
                    new SerilogLidgrenEvents(logger));
                var config = new NetNodeConfig { SendTimeoutSec = 30, ConnectTimeoutSec = 30 };
                var node = new ClientNode(
                //new[] { "127.0.0.1:20001" },

                new[] { "rurounisfcluster.westeurope.cloudapp.azure.com:20001" },
                transport, coreEventLogger, messageSerializer, messageHandlingConfigurator, config: config);

                try
                {
                    node.Start();
                    node.ExecuteChatUserFlow(roomName).Wait();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            Thread.Sleep(-1);
        }
        public void GivenNobodyListens_WhenConnecting_ThenConnectionWillTimeout()
        {
            var config = new NetNodeConfig() { ConnectTimeoutSec = 1 };
            using (var node = CreateNode("node1", 40001, config))
            {
                node.Start();

                Func<Task<INetChannel>> act = () => node.Connect(new IPEndPoint(IPAddress.Loopback, 50123));

                act.ShouldThrow<ConnectionFailedException>();
            }
        }
        static void Main(string[] args)
        {
            int port = 12345;

            var messageSerializer = new ProtobufMessageSerializer(
                new Message[] { new JoinRoom(), new Say(), new RoomEvent(), new JoinRoomResponse() },
                new MessageHeader[] { new OperationHeader() });

            var logger = new LoggerConfiguration()
                .ConfigureMOUSETypesDestructure()
                .MinimumLevel.Verbose()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            var coreEventLogger = new SerilogCoreEvents(logger);

            var transport = new LidgrenNetProvider(
                new NetPeerConfiguration("Public")
                {
                    MaximumConnections = 10,
                    AcceptIncomingConnections = true,
                    Port = port,
                    LocalAddress = IPAddress.Loopback
                },
                new SerilogLidgrenEvents(logger));

            var netConfig = new NetNodeConfig()
            {
                ConnectTimeoutSec = 30,
                SendTimeoutSec = 30
            };

            var bufferPool = new WcfBufferPool();

            var node = new NetNode<NetChannel>("server", transport, coreEventLogger, messageSerializer, config: netConfig,
                channelFactory: (n, transportChannel) =>
                    new AsyncProcessingNetChannel(builder => builder
                        .UseFiber(Fiber, config => config
                            .Lock<Say>(LockType.Read)
                            .Lock<JoinRoom>(LockType.Write)
                            .Lock<PeerDisconnected>(LockType.Write))
                        .UseConfigurableDispatcher(config => config
                            .HandleMessage<Say>(OnSay)
                            .HandleMessage<JoinRoom>(OnRoomJoin)
                            .HandleMessage<PeerDisconnected>((msg, o) => OnRoomLeave(o.ReplyChannel))),
                        n, transportChannel, messageSerializer, coreEventLogger, netConfig, bufferPool));
            
            node.Start();
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //configure serialization
            var messageSerializer = new ProtobufMessageSerializer(
                new Message[] {new JoinRoom(), new Say(), new RoomEvent(), new JoinRoomResponse()},
                new MessageHeader[] {new OperationHeader()});

            var logger = new LoggerConfiguration()
                .ConfigureMOUSETypesDestructure()
                .MinimumLevel.Verbose()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            var coreEventLogger = new SerilogCoreEvents(logger);

            //configure network transport provider
            var transport = new LidgrenNetProvider(
                new NetPeerConfiguration("Public") { LocalAddress = IPAddress.Loopback },
                new SerilogLidgrenEvents(logger));
            var config = new NetNodeConfig {SendTimeoutSec = 30, ConnectTimeoutSec = 60};


            var node = new NetNode<NetChannel>("client", transport, coreEventLogger, messageSerializer,config : config, 
                channelFactory: (n,transportChannel) =>
                {
                    var peer = new NetChannel(n, transportChannel, messageSerializer, coreEventLogger, config, new WcfBufferPool());
                    //low level channel handling declaration uses Rx channel.OperationReceivedEvent under the hood
                    peer.RegisterHandler<RoomEvent>(msg => Console.WriteLine(msg.UserName + "->" + msg.Text));

                    return peer;
                });

            try
            {
                Run(node).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.ReadKey();
        }