예제 #1
0
 protected void OnNotify(ExcuteAction action)
 {
     if (NotifyReceived != null)
     {
         NotifyReceived(this, new ModelNotificationEvantArgs(action));
     }
 }
예제 #2
0
        private void AcceptCallback(IAsyncResult ar)
        {
            TcpClient client = m_listener.EndAcceptTcpClient(ar);

            m_listener.BeginAcceptTcpClient(m_acceptCallback, null);
            #region 用线程池接收
            //ThreadPool.QueueUserWorkItem(ReceiveCallback, client);
            #endregion

            #region 直接接收
            try
            {
                NetworkStream stream = client.GetStream();
                byte[]        buffer = new byte[sizeof(int)];
                stream.Read(buffer, 0, buffer.Length);
                int count = BitConverter.ToInt32(buffer, 0);
                while (count > 0)
                {
                    ExcuteAction action = new ExcuteAction();
                    action.Deserialize(stream);
                    OnNotify(action);
                    count--;
                }
                client.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #endregion
        }
예제 #3
0
 private void ReceiveCallback(IAsyncResult ar)
 {
     try
     {
         Byte[]       buffer = m_udp.EndReceive(ar, ref m_receivePoint);
         MemoryStream ms     = new MemoryStream(buffer);
         ExcuteAction action = new ExcuteAction();
         action.Deserialize(ms);
         OnNotify(action);
         m_udp.BeginReceive(m_receiveCallback, null);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #4
0
 private void ReceiveCallback(Object threadContext)
 {
     try
     {
         TcpClient     client = threadContext as TcpClient;
         NetworkStream stream = client.GetStream();
         while (stream.DataAvailable)
         {
             ExcuteAction action = new ExcuteAction();
             action.Deserialize(stream);
             OnNotify(action);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #5
0
 public ModelNotificationEvantArgs(ExcuteAction action)
 {
     Action = action;
 }