private void Initializer() { send = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); receive = SocketAsyncEventArgsPool.GetNewAsyncEventArgs(); //绑定异步套接字操作对象的Socket对象 send.AcceptSocket = receive.AcceptSocket = this.baseSocket; receive.Completed += Receive_Completed; send.Completed += Send_Completed; }
private void Send_Completed(object sender, SocketAsyncEventArgsMetadata e) { var iar = e.UserToken as SocketNetworkStream_AsyncResult; if (iar == null) { //出现意外的调用命令 this.Dispose(); return; } if (e.SocketError == SocketError.Success && e.BytesTransferred > 0) { iar.Result = e.BytesTransferred; } else { iar.Result = 0; iar.ex = new System.Exception("远程主机已经关闭连接"); } Send_End(); iar.CallComplete(); }