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 / WebSocket
  • Overview
  • How the WebSocket server works
  • How to use the WebSocket server?
  • "WebSocket server" project
  • Creating a "WebSocket server" project
  • WLanguage events specific to "WebSocket server" projects
  • Execution contexts
  • Specific WLanguage functions that can be used in WebSocket server projects
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Otros
Procedimientos almacenados
Overview
The WebSocket protocol provides a communication channel over a TCP socket for browsers and Web servers. Thus, it is possible to communicate and exchange messages with a Web server, using WEBDEV browser code.
The WebSocket server provided with WEBDEV can be run on Windows and with IIS (IIS 8 or later) only.
Starting with version 27, it is possible to connect to a WebSocket server via a WINDEV application (Windows or Linux) or a WINDEV Mobile application (Android or iOS).
How the WebSocket server works
In an application or Web site, the client sends a request to the server and the server returns the response, such as the content of the requested page.
The use of a WebSocket makes it possible to transmit data associated with the website in real time (e.g., messages in an instant messaging site). With the WebSocket protocol, the client only needs to establish a connection with a Web server. Once established, the communication channel remains open.
The server can independently send all the information it considers useful to the client. If new information is available on the server, the client does not have to send a request.
How to use the WebSocket server?
To use the WebSocket server, you must:
  1. Install the WEBDEV 2024 Application Server, which allows you to manage WebSocket servers ("WebSockets" tab).
    Remark: WEBDEV 26 Application Server or later is required.
  2. Create a "WebSocket server" project. This project is deployed on the Web server (where the WEBDEV Application Server has been installed). It waits for connections sent to it using the WebSocket protocol. This application runs in the background on the server.
  3. Create the project that will query the WebSocket server. This project will send messages to the WebSocket server and process the responses using Socketxxx functions, if necessary. This project can be:
    • A WEBDEV project.
    • A WINDEV project.
    • A WINDEV Mobile project (Android or iOS).
  4. The connection to the WebSocket server can be established from the "client" project via the following functions:
    WebSocketClientConnectEstablece una conexión entre el cliente y un servidor WebSocket.
    WebSocketClientConnectSSLEstablece una conexión SSL entre el cliente y un servidor WebSocket.
Remark: The WEBDEV WebSocket Server can be used with any language that supports this protocol.
"WebSocket server" project

Creating a "WebSocket server" project

To create a "WebSocket server" project:
  1. Go to the WEBDEV home page (or press CTRL + <).
  2. Click "Create a project", then "WebSocket server". The project creation wizard starts.
  3. Enter the project name and location.
  4. Finish the wizard: the project is automatically created.
Caution: This project must not use (internal or external) components, or load libraries (WDL).

WLanguage events specific to "WebSocket server" projects

Several specific WLanguage events are associated with the project:
EventRuntime condition
Global service (loop process)This event is the main event of the WebSocket server. It is called in a loop when the WebSocket server is started.
For example, this event can be used to send a message to one or more clients according to a parameter read in a data file.
You can specify the execution interval of this event using the following syntax:
PROCÉDURE ServiceGlobal()<intervalle=<Durée>>
where <Duration> is the event execution interval. This parameter can be an integer that corresponds to the number of milliseconds, or the duration in text format (e.g., '20 s' or '10 ms'). By default, this event is executed every 10 seconds.
In this event, you can use WebSocketListConnectedClient to get the list of clients connected at the time of execution of the function (keep in mind that this list can be different at each moment).
New connectionExecuted when a client connection is requested (via SocketConnect).
Reminder: The client is a website. The connection request will be made from the browser code of a web page.
This event accepts parameters. This event has the following format:
PROCÉDURE Connexion(Client est un websocketClient)
where <Client> corresponds to a websocketClient variable that contains the characteristics of the client.
Receive a message from a clientExecuted when the client sends a message to the WebSocket server (via SocketWrite).
This event accepts parameters. This event has the following format:
PROCÉDURE ReceptionMessage(Client est un websocketClient,
vMessage est un Variant)
where:
  • <Client> corresponds to a websocketClient variable that contains the characteristics of the client.
  • <vMessage> corresponds to the message sent by the client. The actual type of the stored value is a Unicode string or a Buffer (<vMessage>.Type).
Disconnection of a clientExecuted when the client is disconnected (via SocketClose).
This event accepts parameters. This event has the following format:
PROCÉDURE Deconnexion(Client est un websocketClient)
where <Client> corresponds to a websocketClient variable that contains the characteristics of the client.
Stop global serviceExecuted when the global service is stopped.

Remark: To edit the specific events of a project: on the "Inicio" tab, in the "General" group, expand and select "Project code".

Execution contexts

The global service of the WebSocket server and the connected clients are executed independently. Each is executed in its own context with:
  • its own copy of global variables.
  • its own database context.
  • etc.
Therefore, it is not possible to handle the global context or the context of another client from another context.
WebSocketExecute is used to execute a procedure in the context of a client connected to the WebSocket server. In this case, the execution context is that of the client: during the execution of the procedure, the global variables will be those of the specified client.
WebSocketExecuteGlobalService is used to execute a global procedure in the global context of the WebSocket server. During the execution of the global procedure, the global variables will be those of the global service.
Caution: It may be necessary to set the time interval between two global service calls so that the procedure can be executed.

Specific WLanguage functions that can be used in WebSocket server projects

The following functions can be used in the WebSocket server:
WebSocketDisconnectDesconecta un cliente de un servidor WebSocket.
WebSocketExecuteEjecuta un procedimiento en el contexto de un cliente conectado al servidor WebSocket.
WebSocketExecuteGlobalServiceEjecuta una Procedure global en el contexto del servicio global del servidor WebSocket.
WebSocketListConnectedUserLista los clientes conectados al servidor WebSocket.
WebSocketSendEnvía un mensaje del servidor WebSocket al cliente.
Versión mínima requerida
  • Versión 26
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 04/04/2024

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