/// <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); } }
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); } } }