예제 #1
0
        private void CallBackRecvive(IAsyncResult asyncResult)
        {
            UdpClient c = asyncResult.AsyncState as UdpClient;

            byte[] recvBuf = c.EndReceive(asyncResult, ref mRecvPoint);
            lock (RecvMsgs)
            {
                RecvMsgs.Enqueue(Encoding.UTF8.GetString(recvBuf));
            }
            c.BeginReceive(CallBackRecvive, c);
        }
예제 #2
0
 void AddRecvMsgs(String S)
 {
     bGot_AddRecvMsgs = true;
     Dispatcher.BeginInvoke(new Action(() =>
     {
         if (RecvMsgs.Text.Length == 0)
         {
             RecvMsgs.Text = S;
         }
         else
         {
             RecvMsgs.Text += "\n" + S;
         }
         RecvMsgs.Focus();
         RecvMsgs.CaretIndex = RecvMsgs.Text.Length;
     }), DispatcherPriority.Background);
 }
예제 #3
0
        public void Update(float deltaTime)
        {
            lock (RecvMsgs)
            {
                if (RecvMsgs.Count > 0)
                {
                    string oRecvMsg = RecvMsgs.Dequeue();
                    Recv(oRecvMsg);
                }
            }

            // 包验证超时重发
            for (int i = 0; i < BeenSent.Count; i++)
            {
                Packet packet = BeenSent[i];
                packet.wait = packet.wait + deltaTime;
                if (packet.wait > TimeOut)
                {
                    Send(packet, true);
                }
            }
        }
예제 #4
0
 private void Clear_Click(object sender, RoutedEventArgs e)
 {
     RecvMsgs.Text = "";
     RecvMsgs.Focus();
     RecvMsgs.CaretIndex = RecvMsgs.Text.Length;
 }