private void BeginSend() { if (!this.isSend && this.IsConnected && sendQueue.Count > 0) { this.isSend = true; byte[] data = this.sendQueue.Dequeue(); TcpSendData state = new TcpSendData(); state.Buffer = SocketHelper.ToSendData(data); state.BufferIndex = 0; try { this.socket.BeginSend(state.Buffer, 0, state.Buffer.Length, SocketFlags.None, this.OnSend, state); } catch (Exception ex) { this.OnErrorEvent(ex); } } }
/// <summary> /// 发送数据 /// </summary> /// <param name="data">数据</param> public bool Send(byte[] data) { if (data != null || data.Length > 0 && this.IsConnected) { byte[] buffer = SocketHelper.ToSendData(data); int count = 0; while (count < buffer.Length) { count += this.socket.Send(buffer, count, buffer.Length - count, SocketFlags.None); } return(true); } return(false); }
public override bool Send(byte[] data) { return(base.Send(SocketHelper.ToSendData(data))); }