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); } } }
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 = data; state.BufferIndex = 0; try { this.networkStream.BeginWrite(state.Buffer, 0, state.Buffer.Length, this.OnSend, state); } catch (Exception ex) { this.OnErrorEvent(ex); } } }
private void OnSend(IAsyncResult ar) { try { int sendLength = this.socket.EndSend(ar); TcpSendData state = ar.AsyncState as TcpSendData; state.BufferIndex += sendLength; if (state.BufferIndex < state.Buffer.Length) { this.socket.BeginSend(state.Buffer, state.BufferIndex, state.Buffer.Length - state.BufferIndex, SocketFlags.None, this.OnSend, state); } else { this.isSend = false; this.BeginSend(); } } catch (Exception ex) { this.OnErrorEvent(ex); } }