Changes

Jump to navigation Jump to search
406 bytes added ,  17:06, 31 October 2018
no edit summary
==%ws:connect(path)==
Called directly after a successful WebSocket handshake. The <code>path</code> specifies the path which a client is connected to.: <pre class="brush:xquery">declare %ws:connect('/') function local:connect() { };</pre>
You can specify here how to handle your users, e. g. save a name as a WebSocket attribute. Furthermore, you can check header parameters for validity.
==%ws:close(path)==
Called when the WebSocket closes. The <code>path</code> specifies the path which a client is connected to.: <pre class="brush:xquery">declare %ws:close('/') function local:connect() { };</pre>
The WebSocket is already closed when this annotation is called so there can be no return.
If you get the <code>[basex:ws] WebSocket connection required</code> error, you may be attempting to call WebSocket functions from a non-WebSocket context. If you use a proxy server, check in the configuration if WebSockets are enabled.
=Examples= ==Basic Example==
The following chapter explains how to create a simple basic web application with WebSockets. You can find another example in the BaseX source code.
</pre>
The <code>send</code> function can be called to pass on a string to the server. There are no heart-beats in this example. This means that the connection is terminated if nothing happens for 5 minutes (estandard timeout). gIt will also be closed if you send a message that exceeds the standard text size.  ==Chat Application== In the full distributions of BaseX, you will find a little self-contained chat message) to the serverapplication that demonstrates how WebSockets can be used in practice=Changelog=
There are no heartbeats in this exampleWebSockets werre introduced with Version 9. This means that the connection is terminated if nothing happens for 5 minutes (standard timeout). It will also be closed if you send a message that exceeds the standard text size1.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu