I am using the example from the Socket.IO homepage (http://socket.io/). It works and everything, but there is a huge delay between the time data is sent, and when that data is received on the other end.
I am using XAMPP, I have socket.html in my dir, and navigate to it using “http://localhost/socket.html” in my browser, and I have the server listening on port 8080.
Server:
var io = require('socket.io').listen(8080);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
HTML File:
<html>
<head>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8080');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</head>
<body>
</body>
</html>
I have found the problem.
In the server
I changed:
to
which forces the server to use either WebSockets, Flash Sockets, or long-polling. It wil try to use those in that order. The rememberTransport forces the server and client to forget which connection it used last, and try to connect with the ‘transports’ above.
On the client side I just pretty much did the same thing.
I added:
to the socket constructor. So it looked like:
Now it seems to work perfectly.
Thanks guys.