- Optimizing the connections for an IP address
- Name resolution
- Required permissions
- Required application feature
In french: SocketConnecte
Connects a client computer to a given socket.
- UDP sockets: The UDP protocol being a "connectionless" protocol, SocketConnect cannot be used with the UDP protocol. To send or receive data with the UDP protocol, you must create a UDP socket (SocketCreateUDP) then send/receive data with the "special UDP" syntaxes of SocketWrite and SocketRead.
- SSL sockets: To send or receive data with the SSL protocol, you must create an SSL socket (SocketCreateSSL) and connect to this socket with SocketConnectSSL.
- Communication with robots or with non-WINDEV applications: To simplify the exchanges of data by socket, a transmission mode is initialized by default. For a communication with an external module (non-WINDEV application, robot, ...), this transmission mode can prevent the communications from operating properly. SocketChangeTransmissionMode is used to change this transmission mode (the SocketNoEndTag constant allows you not to modify the frames read and written).
Reminder: A socket is a communication resource used by applications to communicate from one computer to another regardless of the type of network.
Connecting to a socket Hide the details
<Result> = SocketConnect(<Socket name> , <Port number> [, <Address> [, <Maximum timeout>]])
- True if the function was successful,
- False otherwise. If an error occurs, you can get more details on the error with ErrorInfo.
<Socket name>: Character string
Name that will be given to the connection opened on the server socket. This name will be used by all socket functions.
<Port number>: Integer
Port number of the socket. If you are using a socket associated with a preset protocol, use the port number associated with the protocol.
If the socket was created by a WINDEV application, this number must be included between 5 000 and 65 000. In this case, the number must be identical to the port number specified in SocketCreate.
<Address>: Optional character string
Server address. If this parameter is not specified, the server is sought on the current computer. This address can be given in the following format:
- IP address in XXX.XXX.XXX.XXX format (220.127.116.11 for example).
- URL containing the server name (www.windev.com for example). This syntax is recommended.
The address must be the server IP address (not the server name).
<Maximum timeout>: Optional integer or optional Duration
Maximum timeout (in milliseconds) for establishing the connection. This timeout will be used if the server refuses the connection (SocketDeny). In this case, the connection will not be locking. This parameter can correspond to:
This timeout is set to 5000 milliseconds by default (5 seconds). For more details, see the remarks.
- an integer corresponding to the number of milliseconds,
- a Duration variable,
- the duration in a readable format (e.g., 1 s or 10 ms).
Optimizing the connections for an IP address
When an IP address is passed to SocketConnect
, the connection can be optimized by using the following code:
Socket.Option = SocketOptimizeIPConnection
This option is not enabled by default because the connection may fail in some configurations. However, it may be useful in some applications for which the performance is critical.
: To restore the default behavior, simply use the SocketOptionDefault
Socket.Option = SocketOptionDefault
The Android emulator does not use the system of name resolution of the computer on which it is run. This detail is important if your development computer is configured to automatically add a suffix of domain name local to the computer names to resolve. In the Android emulator, the full names must be specified.
For example: If your computer is configured to add the "mydomain.com" suffix to the simple names, the following code:
will attempt to connect to myserver.mydomain.com if it is run directly on the PC and to "myserver" in the Android emulator.
When executed on an Android device, SocketConnect
expects an IP address:
SocketConnect("18.104.22.168") // or a string that contains the IP address.
The call to this function modifies the permissions required by the application.
Required permission : INTERNET
This permission allows the applications to open the network sockets.
Required application feature
When this function is used, an application feature is declared in the application generation wizard.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
This page is also available for…
NO WORK WITH WebSocketServer
the syntax does not work for WebSocketServer in version 26.