X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=demos%2Fwebsocket%2Fws-server.js;fp=demos%2Fwebsocket%2Fws-server.js;h=47a420998f4fb0bf3e752f4a58e1d85b7a484e3b;hb=9f0c24e3e0f610303b9af8ff979c8e4408713cc8;hp=0000000000000000000000000000000000000000;hpb=183b4f02e68279d4984e79b79e06bfcf1861fcbf;p=8sync.git diff --git a/demos/websocket/ws-server.js b/demos/websocket/ws-server.js new file mode 100755 index 0000000..47a4209 --- /dev/null +++ b/demos/websocket/ws-server.js @@ -0,0 +1,48 @@ +#! /usr/bin/env node + +/// 8sync --- Asynchronous programming for Guile +/// Copyright © 2019 Jan (janneke) Nieuwenhuizen +/// +/// This file is part of 8sync. +/// +/// 8sync is free software: you can redistribute it and/or modify it +/// under the terms of the GNU Lesser General Public License as +/// published by the Free Software Foundation, either version 3 of the +/// License, or (at your option) any later version. +/// +/// 8sync is distributed in the hope that it will be useful, +/// but WITHOUT ANY WARRANTY; without even the implied warranty of +/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/// GNU Lesser General Public License for more details. +/// +/// You should have received a copy of the GNU Lesser General Public +/// License along with 8sync. If not, see . + +var server_port = 1236; + +// npm install -g ws +function main () { + var wss = new require ('ws').Server ({port:server_port}); + console.log ('listening: %s', server_port); + wss.on ('connection', function (ws) { + ws.onopen = function () { + console.log ('ws.onopen'); + // process.nextTick (function () { + // ws.send ('Hello Web Socket'); + // ws.close (); + // }); + } + ws.onerror = function (e) { + console.log ('ws.onerror: e=%s', '' + e); + } + ws.onclose = function () { + console.log ('ws.onclose'); + } + ws.onmessage = function (event) { + var msg = event.data; + console.log ('ws.onmessage: msg=%s', msg); + }; + }); +} + +main ();