ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Sockets
  • Optimizing the connections for an IP address
  • Timeout
  • Name resolution
  • Required permissions
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Connects a client computer to a given socket.
Remarks:
  • UDP-type sockets The UDP protocol is not a "connected" protocol, so the SocketConnect function 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 using the SSL protocol, you need to create an SSL socket (function SocketCreateSSL) and connect to it using function SocketConnectSSL.
  • Communication with non-WINDEV automation systems or applications: To simplify data exchange via 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 machine to another, regardless of the type of network.
Example
AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst
IF SocketConnect("Serveur", 8000) = False THEN
	Error("erreur de connexion " + ErrorInfo(errMessage))
END
Syntax
AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst

Connecting to a socket Hide the details

<Result> = SocketConnect(<Socket name> , <Port number> [, <Address> [, <Maximum timeout>]])
<Result>: Boolean
  • 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 specified as follows:
  • IP address in XXX.XXX.XXX.XXX format (125.5.110.100 for example).
  • URL containing the server name (www.windev.com for example). This syntax is recommended.
AndroidAndroid Widget 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:
  • an integer representing the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
This timeout is set to 5000 milliseconds by default (5 seconds). For more details, see the remarks.
Remarks
AndroidAndroid Widget

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.
Remark: To restore default operation, simply use constant DefaultSocketOption:
Socket.Option = SocketOptionDefault
AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst

Timeout

The timeout specified by <Maximum timeout> groups the timeout of two steps:
  • address resolution time: this time cannot be configured, but can be optimized (see below).
  • the maximum timeout for the connection to be accepted by the server. Several cases may occur:
    • the server refuses the connection.
    • the server accepts the connection within the timeout limit.
    • the server is not available.
    • the specified address is invalid.
To optimize the timeout for address resolution (time required to find the address), we advise you to:
  • use a DNS on the network. Therefore, this address will be searched for toward this server and not for each computer (1 search instead of x searches where x represents the number of computers). Each computer must be registered toward this server.
  • or, in the case of an IP address, use the variable Socket.Option variable as follows:
    Socket.Option = SocketOptimizeIPConnection
    iPhone/iPadIOS WidgetMac Catalyst This solution is not available.
AndroidAndroid Widget

Name resolution

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 workstation is configured to add the suffix "mydomain.com" to simple names, the following code:
SocketConnect("monserveur")
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("125.5.110.100") // ou une chaine contenant l'adresse IP.
AndroidAndroid Widget

Required permissions

This function changes the permissions required by the application.
Required permission: INTERNET
This permission allows the applications to open the network sockets.
Component: wd300com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
NO WORK WITH WebSocketServer
the syntax does not work for WebSocketServer in version 26.
CASTILLO / FRANCO
02 Jun. 2022

Last update: 04/02/2025

Send a report | Local help