SocketTools .NET Edition

SocketWrench.Connect Method (String, Int32, SocketProtocol, Int32, SocketOptions, String, Int32)

Establish a connection with a remote host.

[Visual Basic]
Overloads Public Function Connect( _
   ByVal hostName As String, _
   ByVal hostPort As Integer, _
   ByVal protocol As SocketProtocol, _
   ByVal timeout As Integer, _
   ByVal options As SocketOptions, _
   ByVal localAddress As String, _
   ByVal localPort As Integer _
) As Boolean
[C#]
public bool Connect(
   string hostName,
   int hostPort,
   SocketProtocol protocol,
   int timeout,
   SocketOptions options,
   string localAddress,
   int localPort
);

Parameters

hostName
A string which specifies the remote host to establish a connection with. This may specify a host name or an Internet address in dot-notation.
hostPort
An integer which specifies the port number for the connection. This value must be greater than zero and the maximum valid port number is 65535.
protocol
One of the SocketProtocol enumeration values which specify the type of socket to be created.
timeout
An integer value that specifies the number of seconds that the method will wait for the connection to complete before failing the operation and returning to the caller. This value is only meaningful for blocking sockets.
options
One or more of the SocketOptions enumeration flags.
localAddress
A string which specifies the local Internet address that the socket should be bound to. To bind to any valid network interface on the local system, specify the address 0.0.0.0. Applications should only specify a particular address if it is absolutely necessary. In most cases a local address is not required when establishing a client connection.
localPort
An integer value which specifies a local port number that the socket should be bound to. To bind to any available port number, specify a port number of 0. Applications should only specify a particular port number if it is absolutely necessary. The maximum valid port number is 65535.

Return Value

A boolean value which specifies if the connection has been established. If the socket is in blocking mode, a return value of true indicates that the connection has completed and the application may send and receive data from the remote host. If the socket is in non-blocking mode, a return value of true indicates that the socket has been successfully created and the connection is in progress.

When a non-blocking connection has completed, the OnConnect event will be fired. If this method returns false, the connection could not be established and the application should check the value of the LastError property to determine the cause of the failure.

Remarks

When this method is called with Datagram as the specified protocol, it does not actually establish a connection. Instead, it simply establishes a default destination address and port that is used with subsequent calls to the Read and Write methods.

See Also