From d1cbb21fdc49195006fa5813a8cc0bc5495f13b9 Mon Sep 17 00:00:00 2001 From: Wolfram Richter Date: Fri, 4 Aug 2017 22:33:30 +0200 Subject: [PATCH] Updated instructions --- README.md | 14 +++++++------- result/index.html | 6 +++--- result/server.js | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9d697f6..02d025f 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ augmented/replaced by the actual code: // create websocket // function to reconnect web socket // function to send coordinates to server -// draw circle upon message from server +// when a message is received from the server, draw a circle // when web socket is connected... // ...set status message, // ...start sending clicks to server, // ...start reconnect timer and // ...close old socket -// stop sending clicks to server when connection is closed -// reconnect to server upon connection loss +// when connection is closed, stop sending clicks to server +// when connection is lost, reconnect to server ``` 1. Add to the JavaScript to open a web socket back to the server: @@ -144,11 +144,11 @@ augmented/replaced by the actual code: ``` // create websocket server // create pub/sub broker connection -// subscribe to topic on broker and forward messages to websocket clients +// subscribe to topic on broker and forward any message to websocket clients // publish new messages from websocket to topic on broker // when broker connection is established... // ...start publishing new messages from websocket to topic on broker -//cleanup on exit +// when the process exits, clean up ``` 1. Create websocket server @@ -182,7 +182,7 @@ stompit.connect(stompconnection, (err, stompclient) => { 1. Subscribe to topic and forward all publications to websocket clients (below ```// additional code here``` ): ``` -// subscribe to topic on broker and forward messages to websocket clients +// subscribe to topic on broker and forward any message to websocket clients const topic = { destination: '/topic/SampleTopic' } stompclient.subscribe(topic, (err, msg) => { msg.readString('UTF-8', (err, body) => { @@ -219,7 +219,7 @@ ws.on('message', (msg) => { 1. Ensure cleanup on exit (add on stompclient level): ``` -//cleanup on exit +// when the process exits, clean up process.on('exit', () => { stompclient.disconnect() }); ``` diff --git a/result/index.html b/result/index.html index c5f2315..e56eb9d 100644 --- a/result/index.html +++ b/result/index.html @@ -42,7 +42,7 @@ ws.send(JSON.stringify({ x: e.clientX, y: e.clientY })); } - // draw circle upon message from server + // when a message is received from the server, draw a circle ws.onmessage = function(event) { statusline.innerHTML = 'connection #' + numconns + ' ' + event.data; var msg = JSON.parse(event.data); @@ -61,12 +61,12 @@ if (oldws) oldws.close(); } - // stop sending clicks to server when connection is closed + // when connection is closed, stop sending clicks to server ws.onclose = function() { canvas.removeEventListener("mouseup", click, false); }; - // reconnect to server upon connection loss + // when connection is lost, reconnect to server ws.onerror = function() { reconnectafter(1000); }; diff --git a/result/server.js b/result/server.js index f291e50..33a638b 100644 --- a/result/server.js +++ b/result/server.js @@ -24,7 +24,7 @@ const stompconnection = { stompit.connect(stompconnection, (err, stompclient) => { if (err) console.log(err); - // subscribe to topic on broker and forward messages to websocket clients + // subscribe to topic on broker and forward any message to websocket clients const topic = { destination: '/topic/SampleTopic' } stompclient.subscribe(topic, (err, msg) => { msg.readString('UTF-8', (err, body) => { @@ -33,7 +33,7 @@ stompit.connect(stompconnection, (err, stompclient) => { }); }); - // when broker connection is established... + // when websocket connection is established... wss.on('connection', (ws) => { console.log('Client connected'); ws.on('close', () => console.log('Client disconnected')); @@ -53,6 +53,6 @@ stompit.connect(stompconnection, (err, stompclient) => { }); }); - //cleanup on exit + // when the process exits, clean up process.on('exit', () => { stompclient.disconnect() }); });