Created
October 13, 2014 15:58
-
-
Save mattfelsen/9e0bae657104f98c2c95 to your computer and use it in GitHub Desktop.
WebSocket proxy server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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