Connects to a remote server and returns the client's socket handle.
[ lStatus = ] WsConnect ( socket, lRemotePort, vRemoteHost, lTimeout )
The WsConnect procedure syntax has the following parts:
Name |
Type |
Description |
lStatus |
Long |
Status code. Returns 0 is successful, -2 if timeout, -1 if failed. |
socket |
Val ASocket |
A handle identifying an unconnected socket |
lRemotePort |
Val Long |
The port for the socket. |
vRemoteHost |
Val Variant |
The address to be associated with the socket. Address could be Long (for IPv4) or (ATEasy 2024) array of 16 bytes (IPv6) or a string repressing the host address or its IP address. |
lTimeOut |
Val Long |
The length of time in milliseconds to attempt to acquire the socket. |
The WsConnect function establishes a connection to a specified socket. This function should be called by client applications only.
The TCP stream client associates socket names by connecting to the stream server with WsConnect.
Calling WsConnect with the lRemotePort and lRemoteHost parameters is similar to using WsBind, but lRemotePort and lRemoteHost represent the remote port and host, not the local port and host, that are used for WsBind.
vRemoteHost can be specified in one of the following ways:
● Long number representing the IPv4 address (Variant with vtI4)
● Array of 16 bytes representing IPv6 address (ATEasy 2024)
● IPv4 String address, i.e. "10.10.1.1" (ATEasy 2024)
● IPv6 String address, i.e. "fe80::9ce6:108:f120:4704" (ATEasy 2024)
Note: If you computer is configured with a firewall, make sure to allow ATEasy or your application Executable to access the port by creating an outbound or inbound rules for the appropriate port or application.
The following code shows a TCP client connecting with a server:
! Open a socket:
lSocket=WsCreate(m_Settings.lProtocol,0)
! Attempt to connect to a remote server and return the client socket handle in 5 seconds:
lretval=WsConnect(lSocket, lPort, lHost, 5000)
WsAccept, WsBind, WsCreate, WsGetAddress, WsGetName, WsGetPort