AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Sockets
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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 will have no effect.. The socket uses the SocketNoEndTag mode.
  • WebSocketClientConnectSSL is used to establish a secure SSL connection (wss://) with a WebSocket server.
Ejemplo
// Connects to WebSocket server in synchronous mode
// ws://myserver.com/WW_WebsocketServer
IF WebSocketClientConnect("wbsocket", "myserver.com", 80, "/WW_WebsocketServer") THEN
	// Sends a message to the echo server
	IF SocketWrite("wbsocket", "Hello world!") THEN
		// Retrieves the server response
		sMsg is string = SocketRead("wbsocket", True)
		ToastDisplay("server response: " + sMsg)
	END
END
// Connects to WebSocket server in asynchronous mode
// ws://192.168.100.1/MyWebSocketServerProject
WebSocketClientConnect("client", WebSocketClientConnect_Callback, ...
	"192.168.100.1", 80, "MyWebSocketServerProject")

INTERNAL PROCEDURE WebSocketClientConnect_Callback(nEvent, sMessage)
	SWITCH nEvent
		CASE SocketOpening
			SocketWrite("client", "Send message from the browser.")
		CASE SocketMessage
			Info("IncomingData: " + sMessage)
		CASE SocketClosing
			Info("Socket closed", sMessage)
		CASE SocketError
			Error("Socket error")
	END
END
Sintaxis

Establishing an asynchronous connection Ocultar los detalles

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.
WINDEV The address can also correspond to the IP address returned by NetIPAddress.
<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
Clasificación Lógica de negocio / UI: Lógica de negocio
Componente: wd300com.dll
Versión mínima requerida
  • Versión 27
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 28/03/2025

Señalar un error o enviar una sugerencia | Ayuda local