Skip to content

Instantly share code, notes, and snippets.

@jaseemabid
Forked from netroy/Connect-Websocket.js
Created March 25, 2012 17:21
Show Gist options
  • Save jaseemabid/2198440 to your computer and use it in GitHub Desktop.
Save jaseemabid/2198440 to your computer and use it in GitHub Desktop.
Connect with Websockets
var connect = require('connect'),
WebSocketServer = require('websocket').server,
app = connect.createServer();
app.use(connect.static(process.cwd()));
app.use(connect.router(function(app){
app.get("/", function(req, resp) {
resp.write("Hola !");
resp.end();
});
}));
wsServer = new WebSocketServer({
httpServer: app,
autoAcceptConnections: false
});
wsServer.on('request', function(request) {
var connection = request.accept('', request.origin);
connection.on('message', function(message) {
if (message.type === 'utf8') {
connection.sendUTF(message.utf8Data);
}
});
connection.on('close', function(reasonCode, description) {
// Cleanup
});
});
if (!module.parent) {
app.listen(process.env.app_port || 8888);
}
console.log("Push server started");
//foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment