🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

unusual ping times

Started by
30 comments, last by MadProgrammer 22 years, 7 months ago
hehe, you can tell i''m writing the networking part of my game now, just look at the author of the threads...... anyway, i have a simple thread in my game that waits for messages of the type PING (i defined that) and then outputs the time it took to ping the game server. well, this is where the wierd part comes in: i send ping packets to the server (which immediately returns them to me). when i send the packets with very little time inbetween (about 100 times/sec), the ping i''m calculating is about 20-30 (should be right). when i send packets w/ large gaps in between, the ping jumps to 100-300. at the moment the only packets that get sent are my ping ones. why am i getting larger times for spaced out packets? network stats: linksys 10/100 4port router both computers have 10/100 cards in them both computers of good speed does the router keep a temporary cache of routes or something? i''m intrigued
Advertisement
hm, even 20-30 is really slow for LAN it should be near or at 0. does your server really only copy the packet and send it back?
it seems, that yo measure the time between a packet that you have sent and when you send your next packet.
I have this problem too. I use UDP in the game.

SERVER:
I basically have this in winmain

  while(active){   Ret = GetMessage (&msg, NULL, 0, 0);  if((Ret == 0) || (Ret == -1))    active = FALSE;  TranslateMessage(&msg);					  DispatchMessage(&msg);}  


in my winproc I just recvfrom() the message if windows sends a message saying it recieved a packet.

CLIENT:
basically the same thing but using peekmessage()


Here is what is wierd, the client tells me that is about 20 ms of LAG when pinging the server running on the SAME computer. =\

if I change GetMessage() to PeekMessage() the ping times jump to 20 - 60. !!!!!

what am I doing wrong here?
this is how I calculate ping time.

client timestamps a ping packet and sends it to the server, server copies the timestamp into a pong packet and sends it back, client subtracts the timestamp from the current time. viola ping.
client code:

const BYTE PING = 1;

//sending
MSG_PING pmsg;
send(server, (char*)&PING, sizeof(PING), 0);
send(server, (char*)&pmsg, sizeof(pmsg), 0);

//recving and calc (assume there''s a msg there and i''ve already gotten that 1st byte telling me its a PING msg
MSG_PING msg;
int r = recv(server, (char*)&msg, sizeof(msg), 0);
players[0].lastpingtime = GetTickCount() - msg.tickcount;


server code:

if(type == PING)
{
MSG_PING msg;
recv(myClient->sock, (char*)&msg, sizeof(msg), 0);
send(myClient->sock, (char*)&PING, sizeof(PING), 0);
send(myClient->sock, (char*)&msg, sizeof(msg), 0);
}
oops, forgot to tell ya, but the constructor of MSG_PING sets the struct''s tickcount var to GetTickCount()
you should not send 2 packets for requesting a ping

send one packet, the first 2BYTES are the id of te packet, in your example it would be 1. then the next 4 BYTES would be a DWORD with the timestamp. and then send this packet back.


@evilchicken: windows message handling is really slow s you should use an extra thread, wich waits for packets and not the WindowProc routine and you should use blocking sockets...

Edited by - SmG on November 25, 2001 6:30:33 PM
alright, I ripped out the windows async code and put in non-blocking sockets. the application is still single threaded.

basically on the server and client

  winmain(){while(active){if(peekmessage())translatemessage()dispatchmessage()net->loop()}}  


in net->loop

  net::loop(){if(recv() != SOCKET_ERROR){do_something();}}  


I now get ping times anywhere from 40 to 200 ms on the SAME computer, what gives this is worst then just using GetMessage()

Im gonna give multithreading a shot tommorow

use blocking sockets

also, i did what u said, and my ping times are now b/w 10 and 50
weird.

i''ll post code l8er, probly during computer science (mwahaha)

madprog
Have you tried to ping in the command prompt ? I agree that the ping should be near 0 ms for a LAN.
-------------Ban KalvinB !

This topic is closed to new replies.

Advertisement