Class SocketWrapper
Provides a wrapper around a Socket.
public class SocketWrapper : ISocket, IDisposable
- Inheritance
-
SocketWrapper
- Implements
- Inherited Members
Constructors
SocketWrapper(Socket)
Initializes a new instance of the SocketWrapper class.
public SocketWrapper(Socket socket)
Parameters
Properties
Connected
Gets a value indicating whether the socket is connected.
public bool Connected { get; }
Property Value
RemoteIPAddress
Gets the remote IP address of the socket connection.
public string RemoteIPAddress { get; }
Property Value
Stream
Gets a stream for reading and writing data.
public Stream Stream { get; }
Property Value
Methods
Accept()
Accepts a connection for the socket.
public void Accept()
Authenticate(X509Certificate2)
Authenticates over the socket.
public void Authenticate(X509Certificate2 certificate)
Parameters
certificate
X509Certificate2An X509Certificate2 that specifies authentication information.
Bind(EndPoint)
Binds the socket to a local end point.
public void Bind(EndPoint localEndPoint)
Parameters
localEndPoint
EndPointThe local end point to which to bind the socket.
Close()
Closes the socket connection.
public void Close()
Dispose()
Releases all resources used by the SocketWrapper.
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the SocketWrapper and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)
Parameters
Listen(int)
Starts listening to data received over the socket.
public void Listen(int backlog)
Parameters
backlog
intThe number of pending connections to process.
OnAcceptError(ErrorEventArgs)
Raises the AcceptError event.
protected void OnAcceptError(ErrorEventArgs e)
Parameters
e
ErrorEventArgsAn ErrorEventArgs that contains the event data.
OnAccepted(AcceptEventArgs)
Raises the Accepted event.
protected void OnAccepted(AcceptEventArgs e)
Parameters
e
AcceptEventArgsAn AcceptEventArgs that contains the event data.
OnAuthenticateError(ErrorEventArgs)
Raises the AuthenticateError event.
protected void OnAuthenticateError(ErrorEventArgs e)
Parameters
e
ErrorEventArgsAn ErrorEventArgs that contains the event data.
OnAuthenticated(EventArgs)
Raises the Authenticated event.
protected void OnAuthenticated(EventArgs e)
Parameters
OnReceiveError(ErrorEventArgs)
Raises the ReceiveError event.
protected void OnReceiveError(ErrorEventArgs e)
Parameters
e
ErrorEventArgsAn ErrorEventArgs that contains the event data.
OnReceived(ReceivedEventArgs)
Raises the Received event.
protected void OnReceived(ReceivedEventArgs e)
Parameters
e
ReceivedEventArgsA ReceivedEventArgs that contains the event data.
OnSendError(ErrorEventArgs)
Raises the SendError event.
protected void OnSendError(ErrorEventArgs e)
Parameters
e
ErrorEventArgsAn ErrorEventArgs that contains the event data.
OnSent(EventArgs)
Raises the Sent event.
protected void OnSent(EventArgs e)
Parameters
Receive(byte[], int)
Receives data over the socket.
public void Receive(byte[] buffer, int offset)
Parameters
buffer
byte[]The buffer into which the data will be read.
offset
intThe offset into the buffer at which the data will be read.
Send(byte[])
Sends data over the socket.
public void Send(byte[] buffer)
Parameters
buffer
byte[]The data to be sent.
Events
AcceptError
Event raised when an error occurs accepting a connection.
public event EventHandler<ErrorEventArgs> AcceptError
Event Type
Accepted
Event raised when a connection is accepted by the socket.
public event EventHandler<AcceptEventArgs> Accepted
Event Type
AuthenticateError
Event raised when there is an error authenticating over the socket.
public event EventHandler<ErrorEventArgs> AuthenticateError
Event Type
Authenticated
Event raised when authentication is completed over the socket.
public event EventHandler Authenticated
Event Type
ReceiveError
Event raised when there is an error receiving data.
public event EventHandler<ErrorEventArgs> ReceiveError
Event Type
Received
Event raised when data is received by the socket.
public event EventHandler<ReceivedEventArgs> Received
Event Type
SendError
Event raised when there is an error sending data.
public event EventHandler<ErrorEventArgs> SendError
Event Type
Sent
Event raised when data is sent through the socket.
public event EventHandler Sent