websocket: Initial <websocket> client actor support.
[8sync.git] / demos / websocket / ws-client.js
1 #! /usr/bin/env node
2
3 /// 8sync --- Asynchronous programming for Guile
4 /// Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 ///
6 /// This file is part of 8sync.
7 ///
8 /// 8sync is free software: you can redistribute it and/or modify it
9 /// under the terms of the GNU Lesser General Public License as
10 /// published by the Free Software Foundation, either version 3 of the
11 /// License, or (at your option) any later version.
12 ///
13 /// 8sync is distributed in the hope that it will be useful,
14 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 /// GNU Lesser General Public License for more details.
17 ///
18 /// You should have received a copy of the GNU Lesser General Public
19 /// License along with 8sync.  If not, see <http://www.gnu.org/licenses/>.
20
21 var default_server = 'ws://localhost:1236';
22
23 // npm install -g ws
24 function main () {
25   var ws = new require ('ws') (default_server);
26   ws.onopen = function () {
27     console.log ('ws.onopen');
28     process.nextTick (function () {
29       ws.send ('Hello Web Socket');
30     });
31   }
32   ws.onerror = function (e) {
33     console.log ('ws.onerror: e=%s', '' + e);
34   }
35   ws.onclose = function () {
36     console.log ('ws.onclose');
37   }
38   ws.onmessage = function (event) {
39     var msg = event.data;
40     console.log ('ws.onmessage: msg=%s', msg);
41   };
42 }
43
44 main ();