Skip to content

Instantly share code, notes, and snippets.

@ericz
Created April 4, 2011 17:13
Show Gist options
  • Save ericz/901998 to your computer and use it in GitHub Desktop.
Save ericz/901998 to your computer and use it in GitHub Desktop.
example for socket.io issue `Double connections with blocking `alert` or `prompt` during io.connect()`
<script src="http://localhost/socket.io/socket.io.js"></script>
<script>
var socket = new io.Socket('localhost');
socket.connect();
socket.on('connect', function(){
alert("connected");
})
socket.on('message', function(){ })
socket.on('disconnect', function(){ })
</script>
<script>
prompt("wait for a few seconds before clicking ok");
</script>
var http = require('http'),
io = require('socket.io'),
fs = require('fs'),
server = http.createServer(function(req, res){
// your normal server code
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(fs.readFileSync('test.html'));
});
server.listen(80);
// socket.io, I choose you
var socket = io.listen(server);
socket.on('connection', function(client){
console.log("Client connected!");
client.on('message', function(){});
client.on('disconnect', function(){});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment