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); }
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); }
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); } } }
private void Clear_Click(object sender, RoutedEventArgs e) { RecvMsgs.Text = ""; RecvMsgs.Focus(); RecvMsgs.CaretIndex = RecvMsgs.Text.Length; }