C# Class BytesRoad.Net.Sockets.SocketEx

Provide methods for TCP/IP communication through the various types of proxies.
SocketEx class built on top of the System.Net.Sockets.Socket class provided by the .NET Framework. The main advantages of the SocketEx class is that it might be used to communicate with the peer host through the various types of proxies. Thus giving your application the simple way to add so called 'firewall friendly features'.

Following proxy servers are supported: Socks4 Socks4a Socks5, username/password authentication method supported Web proxy (HTTP CONNECT method), basic authentication method supported

Inheritance: IDisposable
Show file Open project: NikolayIT/RatioMaster.NET Class Usage Examples

Private Properties

Property Type Description
BeginTimeoutOp object
CheckDisposed void
DoTimeoutOp object
EndTimeoutOp object
GetTimeoutValue int
Init void
OnTimer void
SetReceiveTimeout void
SetSendTimeout void
SetTimeout void
SocketEx System
StartTimeoutTrack void
StopTimeoutTrack void

Public Methods

Method Description
Accept ( ) : SocketEx

Creates the new instance of the BytesRoad.Net.Sockets.SocketEx class which represents newly created connection.

Accept method accept incoming connection and create new instance of the SocketEx class for it. The SocketEx should be bound before calling this method thus you need to call BytesRoad.Net.Sockets.SocketEx.Bind and BytesRoad.Net.Sockets.SocketEx.Listen methods first (or their asynchronous versions). Web proxy doesn't able to accept incoming connection. So calling this method on the instance of the SocketEx class which is configured to work with the web proxy server (BytesRoad.Net.Sockets.ProxyType.HttpConnect proxy type) will throw the System.InvalidOperationException exception.

BeginAccept ( AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous operation to accept an incoming connection attempt.

BeginAccept method asynchronously accept incoming connection and create new instance of the SocketEx class for it. The SocketEx should be bound before calling this method thus you need to call BytesRoad.Net.Sockets.SocketEx.Bind and BytesRoad.Net.Sockets.SocketEx.Listen methods first (or their asynchronous versions). Web proxy doesn't able to accept incoming connection. So calling this method on the instance of the SocketEx class which is configured to work with the web proxy server (BytesRoad.Net.Sockets.ProxyType.HttpConnect proxy type) will throw the System.InvalidOperationException exception.

BeginBind ( SocketEx socket, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous binding.

The BeginBind method starts an asynchronous binding request. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndBind method is used to retrieve the results of the asynchronous call. It can be called any time after BeginBind; if the asynchronous call has not completed, EndBind will block until it completes.

The behavior of the BeginBind method depends on the proxy type specified while instance of the SocketEx class constructed. Table below represents the behavior of the method for different types of proxy server. Type of proxy server Behavior of the BeginBind method BytesRoad.Net.Sockets.ProxyType.None The socket will be bound locally to the same IP address as the instance of the SocketEx class specified by socket parameter. BytesRoad.Net.Sockets.ProxyType.HttpConnect Web proxy not support binding command. The System.InvalidOperationException would be thrown. BytesRoad.Net.Sockets.ProxyType.Socks4

-or-

BytesRoad.Net.Sockets.ProxyType.Socks4a

-or-

BytesRoad.Net.Sockets.ProxyType.Socks5
The socket will be bound at the proxy server. Port and IP address may be retrieved via BytesRoad.Net.Sockets.SocketEx.LocalEndPoint property. An instance specified by socket parameter must be connected with the remote host through physically the same proxy server as the instance of the SocketEx class on which BeginBind method are called.
BeginConnect ( EndPoint remoteEP, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous connection to the remote host by using specified instance of the System.Net.EndPoint class.

The BeginConnect method starts an asynchronous request for a remote host connection. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndConnect method is used to retrieve the results of the asynchronous call. It can be called any time after BeginConnect; if the asynchronous call has not completed, EndConnect will block until it completes.

BeginConnect ( string hostName, int port, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous connection to the remote host by using host name and port number specified.

The BeginConnect method starts an asynchronous request for a remote host connection. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndConnect method is used to retrieve the results of the asynchronous call. It can be called any time after BeginConnect; if the asynchronous call has not completed, EndConnect will block until it completes.

BeginReceive ( byte buffer, int offset, int size, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous receive operation.

The BeginReceive method starts an asynchronous receive operation. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndReceive method is used to retrieve the results of the asynchronous call. It can be called any time after BeginReceive; if the asynchronous call has not completed, EndReceive will block until it completes.

The receive operation will not completed until the data is available for reading or error occurs. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

BeginSend ( byte buffer, int offset, int size, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous send operation.

The BeginSend method starts an asynchronous send operation. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndSend method is used to retrieve the results of the asynchronous call. It can be called any time after BeginSend; if the asynchronous call has not completed, EndSend will block until it completes.

Send operation will not completed until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the send operation means that the underlying system has had room to buffer your data for a network send.

Bind ( SocketEx socket ) : void

Associates a BytesRoad.Net.Sockets.SocketEx with local end point at the proxy server.

The behavior of the Bind method depends on the proxy type specified while instance of the SocketEx class constructed. Table below represents the behavior of the method for different types of proxy server. Type of proxy server Behavior of the Bind method BytesRoad.Net.Sockets.ProxyType.None The socket will be bound locally to the same IP address as the instance of the SocketEx class specified by socket parameter. BytesRoad.Net.Sockets.ProxyType.HttpConnect Web proxy not support binding command. The System.InvalidOperationException would be thrown. BytesRoad.Net.Sockets.ProxyType.Socks4

-or-

BytesRoad.Net.Sockets.ProxyType.Socks4a

-or-

BytesRoad.Net.Sockets.ProxyType.Socks5 The socket will be bound at the proxy server. Port and IP address may be retrieved via BytesRoad.Net.Sockets.SocketEx.LocalEndPoint property. An instance specified by socket parameter must be connected with the remote host through physically the same proxy server as the instance of the SocketEx class on which Bind method are called.
Close ( ) : void

Releases the resources used by the BytesRoad.Net.Sockets.SocketEx.

Internally simply calls BytesRoad.Net.Sockets.SocketEx.Dispose.

Connect ( EndPoint remoteEP ) : void

Establishes a connection to a remote host by using specified instance of the System.Net.EndPoint class.

Connect method will block until the connection with remote host is established or error occurs.

Connect ( string hostName, int hostPort ) : void

Establishes a connection to a remote host by using host name and port number specified.

Connect method will block until the connection with remote host is established or error occurs.

Dispose ( ) : void

Releases all resources used by the BytesRoad.Net.Sockets.SocketEx.

Call Dispose when you are finished using the BytesRoad.Net.Sockets.SocketEx. The Dispose method leaves the SocketEx in an unusable state. After calling Dispose, you must release all references to the SocketEx so the garbage collector can reclaim the memory that the SocketEx was occupying.

EndAccept ( IAsyncResult asyncResult ) : SocketEx

Completes the asynchronous operation to accept incoming connection.

EndBind ( IAsyncResult asyncResult ) : void

Ends asynchronous binding.

EndBind is a blocking method that completes the asynchronous binding operation started in BytesRoad.Net.Sockets.SocketEx.BeginBind.

EndConnect ( IAsyncResult asyncResult ) : void

Completes the asynchronous connect to remote host.

EndConnect is a blocking method that completes the asynchronous connection to remote host started in the BytesRoad.Net.Sockets.SocketEx.BeginConnect method.

EndReceive ( IAsyncResult asyncResult ) : int

Ends a pending asynchronous receive.

EndReceive is a blocking method that completes the asynchronous receive operation started in the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. The EndReceive method will read as much data as is available up to the number of bytes you specified in the size parameter of the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes.

EndSend ( IAsyncResult asyncResult ) : int

Ends a pending asynchronous send.

EndSend is a blocking method that completes the asynchronous send operation started in the BytesRoad.Net.Sockets.SocketEx.BeginSend method.

EndSend will block until the requested number of bytes are sent. There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the EndSend method means that the underlying system has had room to buffer your data for a network send.

Listen ( int backlog ) : void

Places a BytesRoad.Net.Sockets.SocketEx in a listening state.

Listen causes BytesRoad.Net.Sockets.SocketEx to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance.

Listen function is meaningful only when called on instance of the BytesRoad.Net.Sockets.SocketEx class which configured not to use any type of proxy servers. That is BytesRoad.Net.Sockets.SocketEx.ProxyType property equals to BytesRoad.Net.Sockets.ProxyType.None.

Receive ( byte buffer ) : int

Receives data from the remote host and store it in the specified buffer.

If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

Receive ( byte buffer, int size ) : int

Receives specified amount of data from the remote host and store it in the supplied buffer.

If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

Receive ( byte buffer, int offset, int size ) : int

Receives specified amount of data from the remote host and store it starting from the specified offset in the supplied buffer.

If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

Send ( byte buffer ) : int

Sends all data from the specified buffer to the remote host.

Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.

Send ( byte buffer, int size ) : int

Sends specified amount of data to the remote host.

Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.

Send ( byte buffer, int offset, int size ) : int

Sends specified amount of data starting from the specified position in the supplied buffer to the remote host.

Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.

Shutdown ( SocketShutdown how ) : void

Disables sends and receives.

Calls System.Net.Sockets.Socket.Shutdown method on a socket which is used in underlying layer for communication with proxy server.

SocketEx ( ) : System

Initializes new instance of the BytesRoad.Net.Sockets.SocketEx class for direct connection.

With this constructor the instance of the BytesRoad.Net.Sockets.SocketEx class would be connected to remote host directly. To force connection through the proxy server you need to use other constructor.

SocketEx ( ProxyType proxyType, string proxyServer, int proxyPort, byte proxyUser, byte proxyPassword ) : System

Initializes new instance of the BytesRoad.Net.Sockets.SocketEx class for direct connection or connection through the proxy servers.

If proxy server doesn't support anonymous users and the proxyUser parameter equals to null (Nothing in Visual Basic) then the BytesRoad.Net.Sockets.SocketEx.Connect method will fail.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the BytesRoad.Net.Sockets.SocketEx and optionally releases the managed resources.

This method is called by the public Dispose() method and the Finalize method. Dispose() invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Finalize invokes Dispose with disposing set to false. When the disposing parameter is true, this method releases all resources held by any managed objects that this SocketEx references. This method invokes the Dispose() method of each referenced object.

Private Methods

Method Description
BeginTimeoutOp ( int timeout, IOp op, AsyncCallback cb, object state ) : object
CheckDisposed ( ) : void
DoTimeoutOp ( int timeout, IOp op ) : object
EndTimeoutOp ( IOp op, IAsyncResult ar ) : object
GetTimeoutValue ( int val, string propName ) : int
Init ( ) : void
OnTimer ( object state ) : void
SetReceiveTimeout ( int timeout ) : void
SetSendTimeout ( int timeout ) : void
SetTimeout ( int timeout ) : void
SocketEx ( SocketBase baseSocket ) : System

Used in Accept methods

StartTimeoutTrack ( int timeout ) : void
StopTimeoutTrack ( Exception e ) : void

Method Details

Accept() public method

Creates the new instance of the BytesRoad.Net.Sockets.SocketEx class which represents newly created connection.
Accept method accept incoming connection and create new instance of the SocketEx class for it. The SocketEx should be bound before calling this method thus you need to call BytesRoad.Net.Sockets.SocketEx.Bind and BytesRoad.Net.Sockets.SocketEx.Listen methods first (or their asynchronous versions). Web proxy doesn't able to accept incoming connection. So calling this method on the instance of the SocketEx class which is configured to work with the web proxy server (BytesRoad.Net.Sockets.ProxyType.HttpConnect proxy type) will throw the System.InvalidOperationException exception.
/// The object was disposed. /// /// The operation is unsupported. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Accept ( ) : SocketEx
return SocketEx

BeginAccept() public method

Begins an asynchronous operation to accept an incoming connection attempt.
BeginAccept method asynchronously accept incoming connection and create new instance of the SocketEx class for it. The SocketEx should be bound before calling this method thus you need to call BytesRoad.Net.Sockets.SocketEx.Bind and BytesRoad.Net.Sockets.SocketEx.Listen methods first (or their asynchronous versions). Web proxy doesn't able to accept incoming connection. So calling this method on the instance of the SocketEx class which is configured to work with the web proxy server (BytesRoad.Net.Sockets.ProxyType.HttpConnect proxy type) will throw the System.InvalidOperationException exception.
/// The object was disposed. /// /// The operation is unsupported. ///
public BeginAccept ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

BeginBind() public method

Begins an asynchronous binding.
The BeginBind method starts an asynchronous binding request. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndBind method is used to retrieve the results of the asynchronous call. It can be called any time after BeginBind; if the asynchronous call has not completed, EndBind will block until it completes.

The behavior of the BeginBind method depends on the proxy type specified while instance of the SocketEx class constructed. Table below represents the behavior of the method for different types of proxy server. Type of proxy server Behavior of the BeginBind method BytesRoad.Net.Sockets.ProxyType.None The socket will be bound locally to the same IP address as the instance of the SocketEx class specified by socket parameter. BytesRoad.Net.Sockets.ProxyType.HttpConnect Web proxy not support binding command. The System.InvalidOperationException would be thrown. BytesRoad.Net.Sockets.ProxyType.Socks4

-or-

BytesRoad.Net.Sockets.ProxyType.Socks4a

-or-

BytesRoad.Net.Sockets.ProxyType.Socks5
The socket will be bound at the proxy server. Port and IP address may be retrieved via BytesRoad.Net.Sockets.SocketEx.LocalEndPoint property. An instance specified by socket parameter must be connected with the remote host through physically the same proxy server as the instance of the SocketEx class on which BeginBind method are called.
/// The object was disposed. /// /// The operation is unsupported. ///
public BeginBind ( SocketEx socket, AsyncCallback callback, object state ) : IAsyncResult
socket SocketEx /// An instance of the /// class which already connected to the remote host through the proxy /// server. See remarks for more details. ///
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

BeginConnect() public method

Begins an asynchronous connection to the remote host by using specified instance of the System.Net.EndPoint class.
The BeginConnect method starts an asynchronous request for a remote host connection. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndConnect method is used to retrieve the results of the asynchronous call. It can be called any time after BeginConnect; if the asynchronous call has not completed, EndConnect will block until it completes.

/// The object was disposed. /// /// The remoteEP parameter is null (Nothing in Visual Basic). ///
public BeginConnect ( EndPoint remoteEP, AsyncCallback callback, object state ) : IAsyncResult
remoteEP System.Net.EndPoint /// An instance of the class which /// represents remote end point to connect to. ///
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

BeginConnect() public method

Begins an asynchronous connection to the remote host by using host name and port number specified.
The BeginConnect method starts an asynchronous request for a remote host connection. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndConnect method is used to retrieve the results of the asynchronous call. It can be called any time after BeginConnect; if the asynchronous call has not completed, EndConnect will block until it completes.

/// The object was disposed. /// /// The hostName parameter is null (Nothing in Visual Basic). /// /// port is less than MinPort. ///-or- /// port is greater than MaxPort. ///
public BeginConnect ( string hostName, int port, AsyncCallback callback, object state ) : IAsyncResult
hostName string The name of the remote host.
port int Port number on the remote host.
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

BeginReceive() public method

Begins an asynchronous receive operation.
The BeginReceive method starts an asynchronous receive operation. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndReceive method is used to retrieve the results of the asynchronous call. It can be called any time after BeginReceive; if the asynchronous call has not completed, EndReceive will block until it completes.

The receive operation will not completed until the data is available for reading or error occurs. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// offset is less than 0. /// -or- /// offset is greater than the length of buffer. /// -or- /// size is less than 0. /// -or- /// size is greater than the length of buffer minus /// the value of the offset parameter. ///
public BeginReceive ( byte buffer, int offset, int size, AsyncCallback callback, object state ) : IAsyncResult
buffer byte Buffer to store the received data.
offset int The location in buffer to store the received data.
size int The number of bytes to receive.
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

BeginSend() public method

Begins an asynchronous send operation.
The BeginSend method starts an asynchronous send operation. It returns immediately and does not wait for the asynchronous call to complete.

The BytesRoad.Net.Sockets.SocketEx.EndSend method is used to retrieve the results of the asynchronous call. It can be called any time after BeginSend; if the asynchronous call has not completed, EndSend will block until it completes.

Send operation will not completed until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the send operation means that the underlying system has had room to buffer your data for a network send.

/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// offset is less than 0. /// -or- /// offset is greater than the length of buffer. /// -or- /// size is less than 0. /// -or- /// size is greater than the length of buffer minus /// the value of the offset parameter. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public BeginSend ( byte buffer, int offset, int size, AsyncCallback callback, object state ) : IAsyncResult
buffer byte Data to send.
offset int The position in the data buffer at which to begin sending data.
size int The number of bytes to send.
callback AsyncCallback /// The AsyncCallback delegate. ///
state object /// An object containing state information for this request. ///
return IAsyncResult

Bind() public method

Associates a BytesRoad.Net.Sockets.SocketEx with local end point at the proxy server.
The behavior of the Bind method depends on the proxy type specified while instance of the SocketEx class constructed. Table below represents the behavior of the method for different types of proxy server. Type of proxy server Behavior of the Bind method BytesRoad.Net.Sockets.ProxyType.None The socket will be bound locally to the same IP address as the instance of the SocketEx class specified by socket parameter. BytesRoad.Net.Sockets.ProxyType.HttpConnect Web proxy not support binding command. The System.InvalidOperationException would be thrown. BytesRoad.Net.Sockets.ProxyType.Socks4

-or-

BytesRoad.Net.Sockets.ProxyType.Socks4a

-or-

BytesRoad.Net.Sockets.ProxyType.Socks5
The socket will be bound at the proxy server. Port and IP address may be retrieved via BytesRoad.Net.Sockets.SocketEx.LocalEndPoint property. An instance specified by socket parameter must be connected with the remote host through physically the same proxy server as the instance of the SocketEx class on which Bind method are called.
/// The object was disposed. /// /// The operation is unsupported. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Bind ( SocketEx socket ) : void
socket SocketEx /// An instance of the /// class which already connected to the remote host through the proxy /// server. See remarks for more details. ///
return void

Close() public method

Releases the resources used by the BytesRoad.Net.Sockets.SocketEx.
Internally simply calls BytesRoad.Net.Sockets.SocketEx.Dispose.
public Close ( ) : void
return void

Connect() public method

Establishes a connection to a remote host by using specified instance of the System.Net.EndPoint class.
Connect method will block until the connection with remote host is established or error occurs.
/// The object was disposed. /// /// The remoteEP parameter is null (Nothing in Visual Basic). /// /// An error occurred when attempting to access /// the socket used to complete requested operation. ///
public Connect ( EndPoint remoteEP ) : void
remoteEP System.Net.EndPoint /// An instance of the class which /// represents remote end point to connect to. ///
return void

Connect() public method

Establishes a connection to a remote host by using host name and port number specified.
Connect method will block until the connection with remote host is established or error occurs.
/// The object was disposed. /// /// The hostName parameter is null (Nothing in Visual Basic). /// /// port is less than MinPort. ///-or- /// port is greater than MaxPort. /// /// An error occurred when attempting to access /// the socket used to complete requested operation. ///
public Connect ( string hostName, int hostPort ) : void
hostName string /// The name of the remote host. ///
hostPort int /// The port number on the remote host. ///
return void

Dispose() public method

Releases all resources used by the BytesRoad.Net.Sockets.SocketEx.
Call Dispose when you are finished using the BytesRoad.Net.Sockets.SocketEx. The Dispose method leaves the SocketEx in an unusable state. After calling Dispose, you must release all references to the SocketEx so the garbage collector can reclaim the memory that the SocketEx was occupying.
public Dispose ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by the BytesRoad.Net.Sockets.SocketEx and optionally releases the managed resources.
This method is called by the public Dispose() method and the Finalize method. Dispose() invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Finalize invokes Dispose with disposing set to false. When the disposing parameter is true, this method releases all resources held by any managed objects that this SocketEx references. This method invokes the Dispose() method of each referenced object.
protected Dispose ( bool disposing ) : void
disposing bool /// true to release both managed and unmanaged resources; /// false to release only unmanaged resources. ///
return void

EndAccept() public method

Completes the asynchronous operation to accept incoming connection.
/// The object was disposed. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndAccept ( IAsyncResult asyncResult ) : SocketEx
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for /// this asynchronous operation. ///
return SocketEx

EndBind() public method

Ends asynchronous binding.
EndBind is a blocking method that completes the asynchronous binding operation started in BytesRoad.Net.Sockets.SocketEx.BeginBind.
/// The object was disposed. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndBind ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for /// this asynchronous operation. ///
return void

EndConnect() public method

Completes the asynchronous connect to remote host.
EndConnect is a blocking method that completes the asynchronous connection to remote host started in the BytesRoad.Net.Sockets.SocketEx.BeginConnect method.
/// The object was disposed. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndConnect ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for /// this asynchronous operation. ///
return void

EndReceive() public method

Ends a pending asynchronous receive.
EndReceive is a blocking method that completes the asynchronous receive operation started in the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. The EndReceive method will read as much data as is available up to the number of bytes you specified in the size parameter of the BytesRoad.Net.Sockets.SocketEx.BeginReceive method. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes.
/// The object was disposed. /// /// asyncResult is a null reference /// (Nothing in Visual Basic). /// /// asyncResult was not returned by a call to the /// /// method. /// /// EndReceive was previously called for the /// asynchronous receiving. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndReceive ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for this asynchronous operation. ///
return int

EndSend() public method

Ends a pending asynchronous send.
EndSend is a blocking method that completes the asynchronous send operation started in the BytesRoad.Net.Sockets.SocketEx.BeginSend method.

EndSend will block until the requested number of bytes are sent. There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the EndSend method means that the underlying system has had room to buffer your data for a network send.

/// The object was disposed. /// /// asyncResult is a null reference /// (Nothing in Visual Basic). /// /// asyncResult was not returned by a call to the /// /// method. /// /// EndSend was previously called for the /// asynchronous receiving. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public EndSend ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult /// An /// IAsyncResult /// that stores state information for this asynchronous operation. ///
return int

Listen() public method

Places a BytesRoad.Net.Sockets.SocketEx in a listening state.
Listen causes BytesRoad.Net.Sockets.SocketEx to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance.

Listen function is meaningful only when called on instance of the BytesRoad.Net.Sockets.SocketEx class which configured not to use any type of proxy servers. That is BytesRoad.Net.Sockets.SocketEx.ProxyType property equals to BytesRoad.Net.Sockets.ProxyType.None.

/// The object was disposed. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Listen ( int backlog ) : void
backlog int Lenght of the buffer where incoming connections are queued.
return void

Receive() public method

Receives data from the remote host and store it in the specified buffer.
If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Receive ( byte buffer ) : int
buffer byte /// Buffer to store the received data. ///
return int

Receive() public method

Receives specified amount of data from the remote host and store it in the supplied buffer.
If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// size exceeds the size of buffer. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Receive ( byte buffer, int size ) : int
buffer byte Buffer to store the received data.
size int The number of bytes to receive.
return int

Receive() public method

Receives specified amount of data from the remote host and store it starting from the specified offset in the supplied buffer.
If no data is available for reading, the Receive method will block until data is available. You can use the BytesRoad.Net.Sockets.SocketEx.Available property to determine if data is available for reading. When BytesRoad.Net.Sockets.SocketEx.Available is non-zero, retry the receive operation.

The Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the BytesRoad.Net.Sockets.SocketEx connection with the BytesRoad.Net.Sockets.SocketEx.Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.

/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// offset is less than 0. /// -or- /// offset is greater than the length of buffer. /// -or- /// size is less than 0. /// -or- /// size is greater than the length of buffer minus /// the value of the offset parameter. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Receive ( byte buffer, int offset, int size ) : int
buffer byte Buffer to store the received data.
offset int The location in buffer to store the received data.
size int The number of bytes to receive.
return int

Send() public method

Sends all data from the specified buffer to the remote host.
Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Send ( byte buffer ) : int
buffer byte Data to send.
return int

Send() public method

Sends specified amount of data to the remote host.
Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// size is less than 0 or exceeds the size of buffer. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Send ( byte buffer, int size ) : int
buffer byte Data to send.
size int The number of bytes to send.
return int

Send() public method

Sends specified amount of data starting from the specified position in the supplied buffer to the remote host.
Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// offset is less than 0. /// -or- /// offset is greater than the length of buffer. /// -or- /// size is less than 0. /// -or- /// size is greater than the length of buffer minus /// the value of the offset parameter. /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Send ( byte buffer, int offset, int size ) : int
buffer byte Data to send.
offset int The position in the data buffer at which to begin sending data.
size int The number of bytes to send.
return int

Shutdown() public method

Disables sends and receives.
Calls System.Net.Sockets.Socket.Shutdown method on a socket which is used in underlying layer for communication with proxy server.
/// The object was disposed. ///
public Shutdown ( SocketShutdown how ) : void
how SocketShutdown /// One of the /// values that specifies the operation that will no longer be allowed. ///
return void

SocketEx() public method

Initializes new instance of the BytesRoad.Net.Sockets.SocketEx class for direct connection.
With this constructor the instance of the BytesRoad.Net.Sockets.SocketEx class would be connected to remote host directly. To force connection through the proxy server you need to use other constructor.
public SocketEx ( ) : System
return System

SocketEx() public method

Initializes new instance of the BytesRoad.Net.Sockets.SocketEx class for direct connection or connection through the proxy servers.
If proxy server doesn't support anonymous users and the proxyUser parameter equals to null (Nothing in Visual Basic) then the BytesRoad.Net.Sockets.SocketEx.Connect method will fail.
public SocketEx ( ProxyType proxyType, string proxyServer, int proxyPort, byte proxyUser, byte proxyPassword ) : System
proxyType ProxyType /// Specifies the type of the proxy server to /// be used for communication with remote end point. /// One of the values. ///
proxyServer string The host name of the proxy server.
proxyPort int The port number of the proxy server.
proxyUser byte /// The user name which would be used with proxy server /// in authentication procedure. ///
proxyPassword byte /// The password which would be used with proxy server /// in authentication procedure. ///
return System