diegodfsd
7/26/2011 - 3:59 AM

server nodejs

server nodejs

var express = require('express')
   ,io = require('socket.io');

server = express.createServer(function(req, res){
	res.writeHead(200, { 'Content-Type' : 'text/html' });
	res.end('<h1>Running server nodejs</h1>');
});

server.listen(9090, function(){
	adr = server.address();
	console.log('Server is running on', adr.address, ':', adr.port);
});

var sio = io.listen(server);

sio.sockets.on('connection', function(socket){
	socket.on('message', function(m){
		console.log('Receveid message: ', m);
		socket.broadcast.emit('message', m);
	});
});