Exemplo n.º 1
0
        /// <summary>开始客户端
        ///
        /// </summary>
        public static void StartClient()
        {
            var       host = IPAddress.Loopback;
            const int port = 9991;
            var       connectionFactory = new ClientBootstrap().SetTransport(TransportType.Tcp).Build();

            //New一个Client
            _client = connectionFactory.NewConnection(Node.Empty(), NodeBuilder.BuildNode().Host(host).WithPort(port));
            _client.OnConnection += (address, connection) =>
            {
                connection.BeginReceive(Received);
            };
            _client.OnDisconnection += (address, reason) => { };
            //建立连接
            _client.Open();
            //加入服务端组
            Join();
            //等待输入
            //WaitInput();
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var host         = IPAddress.Loopback;
            var port         = 9991;
            var bootstrapper =
                new ClientBootstrap()
                .SetTransport(TransportType.Tcp).Build();

            TimeClient = bootstrapper.NewConnection(Node.Empty(), NodeBuilder.BuildNode().Host(host).WithPort(port));
            TimeClient.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Confirmed connection with host.");
                connection.BeginReceive(ReceivedCallback);
            };
            TimeClient.OnDisconnection += (address, reason) => Console.WriteLine("Disconnected.");

            Console.Title = string.Format("TimeClient {0}", Process.GetCurrentProcess().Id);
            LoopConnect();
            Console.WriteLine("Requesting time from server...");
            Console.WriteLine("Printing every 1/1000 received messages");
            LoopWrite();
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }