Created
August 5, 2011 19:06
-
-
Save 3rd-Eden/1128254 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<script src="/socket.io/socket.io.js"></script> | |
</head> | |
<body> | |
<div id="output"></div> | |
<script> | |
function write (msg) { | |
var p = document.createElement('p'); | |
p.innerHTML = 'LOG: ' + msg; | |
document.getElementById('output').appendChild(p); | |
}; | |
var socket = io.connect(); | |
socket.on('connect', function () { | |
write('<strong>CONNECT EVENT CALLED</strong>'); | |
socket.emit('print', 'foo'); | |
socket.emit('print', 'bar'); | |
}); | |
socket.on('connecting', function (transport) { | |
write('Trying to connect using ' + transport); | |
}); | |
socket.on('disconnect', function () { | |
write('Aww, disconnected'); | |
}); | |
socket.on('reconnecting', function (delay, attempt) { | |
write('reconnecting, attempt #' + attempt); | |
}); | |
socket.on('reconnect', function () { | |
write('reconnected <3'); | |
}) | |
/*socket.on('done', function () { | |
socket.disconnect(); | |
});*/ | |
</script> | |
</body> | |
</html> |
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 connect = require('connect') | |
, app = connect.createServer(connect.static(__dirname)) | |
, io = require('../../socket.io').listen(app); | |
//io.set('transports', ['xhr-polling']); | |
//io.set('heartbeat interval', .25); | |
//io.set('close timeout', .25); | |
io.sockets.on('connection', function (socket) { | |
var messages = []; | |
socket.on('print', function (msg) { | |
if (messages.indexOf(msg) >= 0) { | |
console.error('duplicate message', msg); | |
} | |
console.log('has message', msg); | |
messages.push(msg); | |
if (messages.length == 2) { | |
socket.emit('done'); | |
} | |
}); | |
}); | |
app.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment