Exemplo n.º 1
0
        private void client_OnReceive(object sender, ReceiveEventArgs e)
        {
            Message message = null;
            if (null != protocol)
                message = protocol.Parse(e.Read(10));
            else
            {
                message = new Message(e.Read());
            }
            string text = string.Format("recv: <--- {0}", e.Read());
            WriteToLog(text);

            if (message.Parsed)
                DispatchState(message.Command, message.Parameters);
            dtTime = DateTime.Now;
        }
Exemplo n.º 2
0
 private void ReceiveData()
 {
     while (this.isConnected)
     {
         try
         {
             byte[] buffer = new byte[0x400];
             if (this.client.Receive(buffer, SocketFlags.Peek) != 0)
             {
                 ReceiveEventArgs e = new ReceiveEventArgs(this.client, null);
                 this.OnReceive(this, e);
             }
             else
             {
                 this.isConnected = false;
                 if (this.OnServerClosed != null)
                 {
                     this.OnServerClosed(this, new SocketEventArgs(this.hostAddress, this.port));
                 }
             }
             continue;
         }
         catch (Exception)
         {
             this.isConnected = false;
             if (this.OnServerClosed != null)
             {
                 this.OnServerClosed(this, new SocketEventArgs(this.hostAddress, this.port));
             }
             continue;
         }
     }
     this.Close();
 }