Created
March 13, 2013 09:53
-
-
Save YoshihitoAso/5150663 to your computer and use it in GitHub Desktop.
[Node.js]Socket.ioのサンプルプログラム(server)
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
require.paths.push('/usr/local/lib/node_modules'); | |
var server = require('http').createServer(function(req, res){ | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.end('server connected'); | |
}); | |
server.listen(1337); | |
var io = require('socket.io').listen(server); | |
io.sockets.on('connection', function (socket) { | |
socket.emit('info', { msg: 'welcome' }); | |
socket.on('msg', function (msg) { | |
io.sockets.emit('msg', {msg: msg}); | |
}); | |
socket.on('disconnect', function(){ | |
socket.emit('info', {msg: 'bye'}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment