System.Net.Sockets.Socket.EndSend C# (CSharp) Method

EndSend() public method

public EndSend ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int
        public int EndSend(IAsyncResult asyncResult)
        {
            SocketError errorCode;
            int bytesTransferred = EndSend(asyncResult, out errorCode);
            if (errorCode != SocketError.Success)
            {
                throw new SocketException((int)errorCode);
            }
            return bytesTransferred;
        }

Same methods

Socket::EndSend ( IAsyncResult asyncResult, SocketError &errorCode ) : int

Usage Example

示例#1
0
        protected void SendCommand(Socket socket, string command, CommandSentEventHandler callback, bool closeConnection = false)
        {
            try
            {
                Wait();
                var byteData = DongleEncoding.Default.GetBytes(command);
                socket.BeginSend(byteData, 0, byteData.Length, 0, asyncResult =>
                {
                    int bytesSent;
                    try
                    {
                        bytesSent = socket.EndSend(asyncResult);
                    }
                    catch (Exception exception)
                    {
                        if (OnErrorOcurred != null)
                        {
                            OnErrorOcurred(exception);
                        }
                        if (OnSocketDisconnected != null)
                        {
                            OnSocketDisconnected(socket);
                        }
                        return;
                    }

                    IsSending = false;

                    if (callback != null)
                    {
                        callback(command, bytesSent);
                    }
                    if (closeConnection)
                    {
                        try
                        {
                            socket.Disconnect(false);
                            if (OnSocketDisconnected != null)
                            {
                                OnSocketDisconnected(socket);
                            }
                        }
                        catch (Exception exception)
                        {
                            if (OnErrorOcurred != null)
                            {
                                OnErrorOcurred(exception);
                            }
                        }                        
                    }
                }, null);
            }
            catch (Exception)
            {                
                if (OnSocketDisconnected != null)
                {
                    OnSocketDisconnected(socket);
                }
            }            
        }
All Usage Examples Of System.Net.Sockets.Socket::EndSend