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
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Allows you to establish a non-secure connection (ws://) with a WebSocket server. Once the connection is established, the WebSocket can be handled like a standard socket, thus allowing you to use SocketRead, SocketWrite, SocketClose or SocketExist.
Remarks:
  • This function has two syntaxes. A synchronous (with a timeout and a return value) and an asynchronous connection syntax (with a callback procedure).
  • With a socket created by function WebSocketClientConnect, function SocketChangeTransmissionMode has no effect.. The socket uses the SocketNoEndTag mode.
  • WebSocketClientConnectSSL is used to establish a secure SSL connection (wss://) with a WebSocket server.
Example
// Se connecte au serveur de websocket en mode SYNCHRONE
// ws://monserveur.com/WW_WebsocketServeur
IF WebSocketClientConnect("wbsocket", "monserveur.com", 80, "/WW_WebsocketServeur") THEN
	// Envoie une chaîne au serveur d'echo
	IF SocketWrite("wbsocket","Bonjour le monde!") THEN
		// Récupère la réponse du serveur
		sMsg is string = SocketLit("wbsocket", True)
		ToastDisplay("réponse du serveur: " + sMsg)
	END
END
// Se connecte au serveur de websocket en mode ASYNCHRONE
// ws://192.168.100.1/MonProjetServeurWebSocket
WebSocketClientConnect("client", WebSocketClientConnecte_Callback, ...
	"192.168.100.1", 80, "MonProjetServeurWebSocket")

INTERNAL PROCEDURE WebSocketClientConnecte_Callback(nEvénement, sMessage)
	SWITCH nEvénement
		CASE SocketOpening
			SocketWrite("client", "Envoi message depuis le navigateur.")
		CASE SocketMessage
			Info("Réception d'un message serveur: " + sMessage)
		CASE SocketClosing
			Info("Fermeture du socket", sMessage)
		CASE SocketError
			Error("Erreur du socket")
	END
END
Syntax
WEBDEV - Browser code This syntax is not available in browser code

Establishing a synchronous connection Hide the details

<Result> = WebSocketClientConnect(<Socket name> , <Server address> [, <Port number> [, <Path> [, <Protocols> [, <Maximum timeout>]]]])
<Result>: Boolean
  • True if the connection was established,
  • 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 socket. This name will be used by all socket functions.
<Server address>: Character string
Server address. 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.
WINDEV The address can also correspond to the IP address returned by NetIPAddress.
AndroidAndroid Widget The address must be the server IP address (not the server name).
<Port number>: Optional integer
Port number of the socket. By default, this parameter is 80 (HTTP port).
<Path>: Optional character string
Path to the virtual directory of the server (if any). By default, or if this parameter is an empty string (""), the path corresponds to "/".
<Protocols>: Optional character string
List of protocols supported by the server to establish the connection (for example: "mqtt,soap").. In this list, the different protocols are separated by a comma (","). A (non-exhaustive) list of protocols can be found here: https://www.iana.org/assignments/websocket/websocket.xml
<Maximum timeout>: Optional integer or optional Duration
Maximum timeout (in milliseconds) for establishing the connection. 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).

Establishing an asynchronous connection Hide the details

WebSocketClientConnect(<Socket name> , <WLanguage procedure> , <Server address> [, <Port> [, <Path> [, <Protocols>]]])
<Socket name>: Character string
Name that will be given to the connection opened on the socket. This name will be used by all socket functions.
<WLanguage procedure>: Procedure name
Name of the procedure called when the connection to the server is established. This procedure can be used to send a message to the server with SocketWrite, for example.
For more details on this procedure, see Parameters of the procedure used by WebSocketClientConnect.
WARNING: the procedure is called in the application's main thread:
  • You can access UI controls from the procedure.
  • The process should not be too long, since this could block the user.
<Server address>: Character string
Server address. 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.
WINDEVWEBDEV - Browser code The address can also correspond to the IP address returned by NetIPAddress.
AndroidAndroid Widget The address must be the server IP address (not the server name).
<Port>: Optional integer
Port number of the socket. By default, this parameter is 443 (HTTPS port).
<Path>: Optional character string
Path to the virtual directory of the server (if any). By default, or if this parameter is an empty string (""), the path corresponds to "/".
<Protocols>: Optional character string
List of protocols supported by the server to establish the connection (for example: "mqtt,soap").. In this list, the different protocols are separated by a comma (","). A (non-exhaustive) list of protocols can be found here: https://www.iana.org/assignments/websocket/websocket.xml
Business / UI classification: Business Logic
Component: wd300com.dll
Minimum version required
  • Version 27
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/19/2024

Send a report | Local help