Created
November 25, 2010 18:23
-
-
Save pgte/715760 to your computer and use it in GitHub Desktop.
Socket.IO with Fugue
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
var http = require('http'), | |
sys = require('sys'), | |
fs = require('fs'), | |
io = require('socket.io'), | |
fugue = require('fugue'); | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
var rs = fs.createReadStream(__dirname + '/template.html'); | |
sys.pump(rs, response); | |
}); | |
var socket = io.listen(server); | |
socket.on('connection', function(client) { | |
var username; | |
client.send('Welcome to this socket.io chat server!'); | |
client.send('Please input your username: '); | |
client.on('message', function(message) { | |
if (!username) { | |
username = message; | |
client.send('Welcome, ' + username + '!'); | |
return; | |
} | |
socket.broadcast(username + ' sent: ' + message); | |
}); | |
}); | |
fugue.start(server, 4000, null, 1, {verbose: true}); | |
//server.listen(4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment