Skip to content

Instantly share code, notes, and snippets.

@nkzawa
Created April 13, 2015 17:34
Show Gist options
  • Save nkzawa/81b8050d10d96aa3e96d to your computer and use it in GitHub Desktop.
Save nkzawa/81b8050d10d96aa3e96d to your computer and use it in GitHub Desktop.
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');
});
});
});
{
"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