BeginConnect() public method

public BeginConnect ( ) : TcpClientMessageService
return TcpClientMessageService
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MessageFactory.Register<LoginMessage>();

            Logger.OnInfo += Console.Write;
            Logger.OnError += Console.Write;

            var remoteIp = IPAddress.Parse("127.0.0.1");

            TcpClientMessageService service = new TcpClientMessageService(remoteIp, 9013);

            service.OnConnected += (o, eventArgs) =>
            {
                TcpClientMessageService service2 = o as TcpClientMessageService;
                Logger.InfoLine("Connectd:{0}", service2.RemoteIPEndPoint);

                LoginMessage lognMessage = new LoginMessage
                {
                    Request =
                    {
                        Name = "Hello",
                        Order = 123
                    }
                };

                service2.Write(lognMessage);
            };

            service.OnDisconnected += (o, eventArgs) =>
            {
                TcpClientMessageService service2 = o as TcpClientMessageService;
                Logger.InfoLine("Disconnected:{0}", service2.RemoteIPEndPoint);
            };
            service.OnRead += ServiceOnRead;
            service.OnError += Service_OnError;

            service.BeginConnect();

            Console.Read();
        }