Beispiel #1
0
        private static void Main(string[] args)
        {
            Port = args.Length < 1 ? DEFAULT_PORT : int.Parse(args[0]);
            var ip = IPAddress.Any;

            Console.WriteLine("Starting echo server...");
            Console.WriteLine("Will begin listening for requests on {0}:{1}", ip, Port);
            var bootstrapper =
                new ServerBootstrap()
                    .WorkerThreads(2)
                    .SetTransport(TransportType.Udp)
                    .Build();
            var reactor = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(ip).WithPort(Port));
            reactor.OnConnection += (node, connection) =>
            {
                ServerPrint(node,
                    string.Format("Accepting connection from... {0}:{1}", node.Host, node.Port));
                connection.BeginReceive(Receive);
            };
            reactor.OnDisconnection += (reason, address) => ServerPrint(address.RemoteHost,
                string.Format("Closed connection to... {0}:{1} [Reason:{2}]", address.RemoteHost.Host,
                    address.RemoteHost.Port, reason.Type));

            reactor.Start();
            Console.ReadKey();
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            var host = IPAddress.Any;
            var port = 9991;
            Console.Title = "Server";
            Console.WriteLine("Starting server on {0}:{1}", host, port);
            var executor = new TryCatchExecutor(exception => Console.WriteLine("Unhandled exception: {0}", exception));

            var bootstrapper =
                new ServerBootstrap()
                    .WorkerThreads(2)
                    .Executor(executor)
                    .SetTransport(TransportType.Tcp)
                    .Build();
            var server = bootstrapper.NewReactor(NodeBuilder.BuildNode().Host(host).WithPort(port));
            server.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Connected: {0}", address);
                connection.BeginReceive(Receive);
            };
            server.OnDisconnection += (reason, address) =>
                Console.WriteLine("Disconnected: {0}; Reason: {1}", address.RemoteHost, reason.Type);
            server.Start();
            Console.WriteLine("Running, press any key to exit");
            Console.ReadKey();
            Console.WriteLine("Shutting down...");
            server.Stop();
            Console.WriteLine("Terminated");
        }
Beispiel #3
0
 private void Run()
 {
     var bootstrapper =
         new ServerBootstrap()
             .WorkerThreads(4)
             .SetTransport(TransportType.Udp)
             .Build();
     _reactor = bootstrapper.NewReactor(
         NodeBuilder.BuildNode()
             .Host(HostIp)
             .WithPort(HostPort));
     _reactor.OnConnection += (node, connection) =>
     {
         //ServerPrint(node,
         //    string.Format("Accepting connection from... {0}:{1}", node.Host, node.Port));
         connection.BeginReceive(UdpPackerReceiveCallback);
     };
     //reactor.OnDisconnection += (reason, address) => ServerPrint(address.RemoteHost,
     //    string.Format("Closed connection to... {0}:{1} [Reason:{2}]", address.RemoteHost.Host, address.RemoteHost.Port, reason.Type));
     _reactor.Start();
 }