I started using socket.io for the web game.
Using nodejs express server I tried to write simple test. In this test server writes timestamp to the client and client returns this timestamp. After this, server logs time used for sending there and back.
Result was: ping 500 ms +- 10 ms. And the same results were when I tried to do it with another computer in the local network.
So, I think, delay is so hi because of TCP Nagle algorithm or something similar. Does anybody knows how to tell nodejs server to flush data as it appears without waiting?
Server code:
var express = require('express'), socketio = require('socket.io');
var app = express.createServer();
var io = socketio.listen(app);
app.use(express.static(__dirname + ''));
app.listen(80);
io.set('transports', ['websocket', 'flashsocket']);
io.sockets.on('connection', function (socket) {
socket.json.send({'message' : 'start'});
socket.on('message', function (msg) {
var time = (new Date()).getTime();
console.log("PING WAS: "+(time - msg.timestamp)+" ms");
socket.json.send({'timestamp' : (new Date()).getTime()});
});
});
Client code:
window.onload = function() {
socket = io.connect('http://localhost:80');
socket.on('message', function (msg) {
socket.json.send({'timestamp' : msg.timestamp});
});
};