Skip to content

Commit

Permalink
Updated instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
wrichter committed Aug 4, 2017
1 parent 9be2ce1 commit d1cbb21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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() });
```

Expand Down
6 changes: 3 additions & 3 deletions result/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};
Expand Down
6 changes: 3 additions & 3 deletions result/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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'));
Expand All @@ -53,6 +53,6 @@ stompit.connect(stompconnection, (err, stompclient) => {
});
});

//cleanup on exit
// when the process exits, clean up
process.on('exit', () => { stompclient.disconnect() });
});

0 comments on commit d1cbb21

Please sign in to comment.