Websocket server live.

master
Ben Burlingham 5 years ago
parent 530d3bffc5
commit f2eca30432
  1. 13
      package-lock.json
  2. 7
      package.json
  3. 33
      ricochet.html
  4. 11
      server.js

13
package-lock.json generated

@ -0,0 +1,13 @@
{
"name": "ricochet",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"ws": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
"integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w=="
}
}
}

@ -4,8 +4,11 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node server.js"
},
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"ws": "^7.3.0"
}
}

@ -121,6 +121,39 @@
<script>
// TODO dynamic sizing of squares based on available height
// TODO dynamic move population
// TODO move websocket server to /core
// TODO dynamic socket server resolution
// TODO namespace server to /ricochet
// https://github.com/websockets/ws
// const WebSocket = require('ws');
// const ws = new WebSocket('ws://www.host.com/path');
// ws.on('open', function open() {
// ws.send('something');
// });
// ws.on('message', function incoming(data) {
// console.log(data);
// });
// BROWSER
var connection = new WebSocket('ws://localhost:8080/', ['soap', 'xmpp']);
// When the connection is open, send some data to the server
connection.onopen = function () {
connection.send('Ping'); // Send the message 'Ping' to the server
};
// Log errors
connection.onerror = function (error) {
console.log('WebSocket Error ' + error);
};
// Log messages from the server
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
};
const board = document.getElementById('board');
const squaresPerSide = 20;

@ -0,0 +1,11 @@
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});
Loading…
Cancel
Save