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();
        }
Exemplo n.º 2
0
 public virtual void OnSend(TcpClientMessageService service)
 {
     OnSendEvent?.Invoke(this, new MessageEventArgs(this, service));
 }
Exemplo n.º 3
0
 public MessageEventArgs(IMessage message, TcpClientMessageService service)
 {
     Message = message;
     Service = service;
 }