Got first version working. Can connect, send, and receive.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Prerequisites:
|
||||
|
||||
1. Install node.js and npm
|
||||
2. npm install ws
|
||||
|
||||
See also,
|
||||
|
||||
http://einaros.github.com/ws/
|
||||
|
||||
To run,
|
||||
|
||||
node example-server.js
|
||||
*/
|
||||
|
||||
"use strict"; // http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
|
||||
var WebSocketServer = require('ws').Server;
|
||||
var http = require('http');
|
||||
|
||||
var server = http.createServer();
|
||||
var wss = new WebSocketServer({server: server, path: '/foo'});
|
||||
wss.on('connection', function(ws) {
|
||||
console.log('/foo connected');
|
||||
ws.on('message', function(data, flags) {
|
||||
if (flags.binary) { return; }
|
||||
console.log('/foo >>> ' + data);
|
||||
if (data == 'goodbye') { ws.send('galaxy'); }
|
||||
if (data == 'hello') { ws.send('world'); }
|
||||
});
|
||||
ws.on('close', function() {
|
||||
});
|
||||
ws.on('error', function(e) {
|
||||
});
|
||||
});
|
||||
server.listen(8126);
|
||||
console.log('Listening on port 8126...');
|
||||
Reference in New Issue
Block a user