Skip to content

Instantly share code, notes, and snippets.

@mattfelsen
Created October 13, 2014 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattfelsen/9e0bae657104f98c2c95 to your computer and use it in GitHub Desktop.
Save mattfelsen/9e0bae657104f98c2c95 to your computer and use it in GitHub Desktop.
WebSocket proxy server
var WebSocket = require('ws');
var WebSocketServer = require('ws').Server;
var client = new WebSocket('ws://localhost:7204/myo/1');
var wss = new WebSocketServer({ port: 9000 });
wss.broadcast = function(data) {
for (var i in this.clients) this.clients[i].send(data, function(){});
};
wss.on('connection', function(ws) {
ws.on('message', function(data) {
client.send(data, function(){});
});
});
client.on('message', function(data) {
wss.broadcast(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment