Connect Method

Establish a connection with a remote server.

Syntax

object.Connect( [RemoteAddress], [RemotePort], [Protocol], [Timeout], [Options], [LocalAddress], [LocalPort] )

Remarks

This method establishes a network connection with a remote server. All arguments are optional. If a given argument is missing, then a corresponding property or properties must be set before attempting the connection, as follows:

RemoteAddress, which may be a hostname or IP address, defaults to the value of the HostAddress property if it is defined. Otherwise, it defaults to the value of the HostName property.

RemotePort specifies the port number that the server is using to listen for connections. If this argument is not specified, the value of the RemotePort property will be used as the default.

Protocol specifies the protocol that should be used when establishing the connection. If this argument is not specified, the value of the Protocol property will be used as the default. One of the following values may be used:

Value Constant Description
6 swProtocolTcp Specifies the Transmission Control Protocol. This protocol provides a reliable, bi-directional byte stream. This is the default protocol.
17 swProtocolUdp Specifies the User Datagram Protocol. This protocol is message oriented, sending data in discrete packets. Note that UDP is unreliable in that there is no way for the sender to know that the receiver has actually received the datagram.

Timeout specifies the amount of time until a blocking operation fails. A value of zero indicates that the control should wait indefinitely for the operation to complete. If this argument is not specified, the value of the Timeout property will be used as the default.

Options specifies one or more socket options which are to be used when establishing the connection. The value is created by combining the options using a bitwise Or operator. Note that if this argument is specified, it will override any property values that are related to that option.

Value Constant Description
1 swOptionBroadcast This option specifies that broadcasting should be enabled for datagrams. This option is invalid for stream sockets.
2 swOptionDontRoute This option specifies default routing should not be used. This option should not be specified unless absolutely necessary.
4 swOptionKeepAlive This option specifies that packets are to be sent to the remote system when no data is being exchanged to keep the connection active. This option is only valid for stream sockets.
8 swOptionReuseAddress This option specifies that the local address can be reused. This option is commonly used by server applications.
16 swOptionNoDelay This option disables the Nagle algorithm, which buffers unacknowledged data and insures that a full-size packet can be sent to the remote host.
32 swOptionInLine This option specifies that out-of-band data should be received inline with the standard data stream. This option is only valid for stream sockets.
&H1000 swOptionSecure This option specifies that a secure SSL connection is to be negotiated and established.

LocalAddress specifies the local IP address of the network adapter that the control should use when establishing the connection. If this argument is not specified, the control will bind to any suitable adapter on the local system. Using a specific local address when establishing a TCP connection is not recommended.

LocalPort specifies the local port number that the control should use when establishing the connection. If this argument is not specified, an appropriate local port number will be assigned for the connection. Using a specific local port number when establishing a TCP connection is not recommended.

Return Value

A value of zero is returned if the connection was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

See Also

HostAddress Property, HostName Property, RemotePort Property, RemoteService Property, Disconnect Method, Broadcast Property, Route Property, KeepAlive Property, ReuseAddress Property, NoDelay Property, InLine Property, Secure Property


Copyright © 2008 Catalyst Development Corporation. All rights reserved.