Changes

Jump to navigation Jump to search
84 bytes removed ,  18:29, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
Called directly after a successful WebSocket handshake. The <code>path</code> specifies the path which a client is connected to:
<syntaxhighlight pre lang="'xquery"'>
declare %ws:connect('/') function local:connect() { };
</syntaxhighlight>
Called when a client message arrives at the server. The <code>path</code> specifies the path which a client is connected to. The <code>message</code> string contains the name of the variable to which the message will be bound:
<syntaxhighlight pre lang="'xquery"'>
declare %ws:message('/', '{$info}') function local:message($info) { };
</syntaxhighlight>
Called when an error occurs. The <code>path</code> specifies the path which a client is connected to. The <code>message</code> string contains the name of the variable to which the message will be bound:
<syntaxhighlight pre lang="'xquery"'>
declare %ws:error('/', '{$error}') function local:error($error) { };
</syntaxhighlight>
Called when the WebSocket closes. The <code>path</code> specifies the path which a client is connected to:
<syntaxhighlight pre lang="'xquery"'>
declare %ws:close('/') function local:connect() { };
</syntaxhighlight>
For accessing connection-specific properties like the HTTP version. The value will be bound to the specified <code>variable</code>. If the property has no value, an optional <code>default</code> value will be assigned instead:
<syntaxhighlight pre lang="'xquery"'>
declare
%ws:close('host', '{$host}')
For establishing a connection to the WebSocket server, it is necessary that the server provides at least one function annotated with a WebSocket annotation. Let’s start by using the annotation <code>%ws:connect('/')</code>. In the connect function, a bidirectional communication with the client can be initialized: attributes such as the id and name of a client can be set, or a welcome message can be emitted to other connected users, and so on.
<syntaxhighlight pre lang="'xquery"'>
declare
%ws:connect('/')
The connect function is sufficient for creating the persistent client/server connection. In order to something sensible with the connection, you should implement a function annotated with <code>%ws:message("/")</code>:
<syntaxhighlight pre lang="'xquery"'>
import module namespace ws = 'http://basex.org/modules/ws';
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu