sncodews - Implement websockets in Extenso
A WebSocket is a network protocol that allows two-way communication between a server and client. Unlike HTTP, which uses a request and response pattern, WebSocket peers can send messages in either direction at any point in time.
WebSockets are often used for chat-based apps and other apps that need to continuously talk between server and client.
sncodews is the program within Extenso to implement the server side.
Websockets enable a faster communication (low latency) between the browser (client) and the server.
Also the server can send a message to the client.
Connection is established at the beginning between the client and the server and they stay connected.
Some example usage:
The program sncodews is used to call a program in Sncode that will implement the communication protocol between the client (usually in Javacript) and the server.
When a new connection is setup in sncodews, a uuid is assign to this connection. This uuid is valid until the user close the connection.
The script executed by sncodews receive the following variables:
sncodews support multiple functions:
%define SNCODEWS_NEW_CONNECTION 0; %define SNCODEWS_CLOSE_CONNECTION 4; %define SNCODEWS_RECEIVE_DATA 6; %define SNCODEWS_SIGUSR1 -10; %define SNCODEWS_SIGUSR2 -12; %define SNCODEWS_NEW_SERVER -1; %define SNCODEWS_SIGTERM -15; function execute_protocol(reason, uuid, data) switch reason do case SNCODEWS_NEW_SERVER: ws::new_server(uuid); endc case SNCODEWS_NEW_CONNECTION: ws::new_connection(uuid); endc case SNCODEWS_CLOSE_CONNECTION: ws::close_connection(uuid); endc case SNCODEWS_RECEIVE_DATA: receive_data(uuid, data); endc case SNCODEWS_SIGUSR1: "Reception de signal\n"; flush(); ws::signal(); endc case SNCODEWS_SIGTERM: ws::close_server(); endc default: "unknown reason: "; reason; "\n"; flush(); endc ends endf execute_protocol(sncodews_reason, sncodews_uuid, sncodews_data);
Written by Pierre Laplante <firstname.lastname@example.org>
1.0 2014-09-09 21:24:14 email@example.comEdit
© 2022 extenso Inc. All rights reserved.