Created
September 12, 2014 02:35
-
-
Save hnq90/fcd858e03435e052f233 to your computer and use it in GitHub Desktop.
Demo Websocket with NodeJS & Socket.io (Server-side)
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 io = require('socket.io'); | |
var socket = io.listen(6666); | |
socket.sockets.on('connection',function(socket){ | |
socket.on('message', function(expr){ | |
console.log('Received expression from client ',expr); | |
try{ | |
socket.send(eval(expr)); | |
} catch(err){ | |
socket.emit("error",err.message); | |
} | |
}); | |
socket.on('disconnect', function(){ | |
console.log('Disconnected'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment