I tried a multiplayer racing game using Node and Socket IO, express. So I tried a simple example to see the delay between the Node server and the clients. I have a drag and drop image in the client. when i move the image ienter code heren one client, it should move across all clients. so basically when i move the image i send the image position to the Node server in json format and then transfer all clients from there. from time to time is approximately 300 ms. Below are the results.
Client 1 sends data to the server at: 286136 (time stamp) Server received at: 286271
Client2 received data at: 286470 Client3 received data at: 286479 Client4 received data at: 286487 Client5 received data at: 286520
The delay between the transition from client1 to client5 is 384 ms. its height is too high for a racing game. here is my server code.
var app = require('express').createServer(); var io = require('socket.io'); var http = require('http'); var http_server = http.createServer(); var server = http.createServer(app); server.listen(3000); var socket = io.listen(server,{ log: false }); socket.sockets.on('connection', function (client) { client.on('message', function (data){ console.log("data arrived to server",new Date().getTime());
1) Is there a way to optimize server code to reduce latency?
2) is the expected latency using Node and websockets?
3) The io socket cannot transmit data asynchronously (I mean at the same time)?
Thanks Kishorevarma
source share