예제 #1
0
파일: UdpServer.cs 프로젝트: zbxpcq/Afx.Lib
 /// <summary>
 /// 发送数据
 /// </summary>
 /// <param name="remoteEP">远程终结点</param>
 /// <param name="data">数据</param>
 public void Send(EndPoint remoteEP, byte[] data)
 {
     if (data != null && data.Length > 0 && this.isAccept)
     {
         UdpSendData state = new UdpSendData();
         state.RemoteEP = remoteEP;
         state.Buffer   = data;
         this.sendQueue.Enqueue(state);
         ThreadPool.QueueUserWorkItem(this.BeginSend);
     }
 }
예제 #2
0
파일: UdpServer.cs 프로젝트: zbxpcq/Afx.Lib
 private void BeginSend(object obj)
 {
     if (!this.isSend && this.isAccept && this.sendQueue.Count > 0)
     {
         this.isSend = true;
         UdpSendData state = this.sendQueue.Dequeue();
         try
         {
             this.socket.BeginSendTo(state.Buffer, 0, state.Buffer.Length, SocketFlags.None, state.RemoteEP, this.OnSend, state.RemoteEP);
         }
         catch (Exception ex)
         {
             this.OnErrorEvent(state.RemoteEP, ex);
         }
     }
 }