Created
April 13, 2015 17:34
-
-
Save nkzawa/81b8050d10d96aa3e96d to your computer and use it in GitHub Desktop.
This file contains 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 http = require('http'); | |
var WebSocket = require('ws'); | |
var bouncy = require('bouncy'); | |
var wsServer = new WebSocket.Server({ noServer: true }); | |
var httpServer = http.createServer(); | |
httpServer.on('upgrade', function (req, socket, head) { | |
wsServer.handleUpgrade(req, socket, head, function(ws){ | |
ws.on('message', function(message) { | |
console.log(message); | |
}); | |
ws.send('hi from server'); | |
}); | |
}); | |
httpServer.listen(8001, function() { | |
var proxy = bouncy(function(req, res, bounce) { | |
bounce(8001); | |
}); | |
proxy.listen(8000, function() { | |
var ws = new WebSocket('ws://localhost:8000'); | |
ws.on('open', function() { | |
ws.on('message', function(message) { | |
console.log(message); | |
}); | |
ws.send('hi from client'); | |
}); | |
}); | |
}); | |
This file contains 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
{ | |
"private": true, | |
"scripts": { | |
"test": "node index.js" | |
}, | |
"dependencies": { | |
"bouncy": "^3.2.2", | |
"ws": "^0.7.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment