Websockets
Built on-top of the HTTP protocol as its upgrade feature. Keeps the connection alive until user closes the tab. Allows to have a full duplex channel between server an unlimited number of clients.
Setting up the connection
For the simplicity there is a special JS script (or let's say a tiny framework) framework.js, which contais all necessary functions. Just put the following lines somewhere in your header file
<script type="text/javascript" src="websockets.js"></script>
<script>
WSPSetHost("<?wsphost?>");
</script>
In the Wolfram's console the message "websocket handshake" should pop up, when you open the webpage.
Send the data to client
There are a few ways, how to do it.
Broadcast to all clients
WebSocketBroadcast[server, expression]
WebSocketBroadcast[server, expression]
Where the expression field should be WL symbol like
WebSocketBroadcast[server, CustomFunction[Table[i, {i,1,10}], "Hello!"]]
This function will be converted to JSON array including all arguments. On the client's side the corresponding function must be
core.CustomFunction = function(args, env) {
console.log(interpretate(args[0]));
console.log(args[1]);
};
If you are sure that the argument will be a string, you can ommit interpretate function, which decodes Mathematica's expressions.
Broadcast to the channel
this section is in the development
Subscribe to the channel
this section is in the development
Send the data to the server
this section is in the development