Advertisement

non-blocking ping

Started by May 18, 2003 10:53 PM
4 comments, last by foofightr 21 years, 8 months ago
Is there any standard way of pinging a client using a non-blocking method? This is intended to be used in a game to keep track of players'' connections, so blocking methods like ICMP and raw packets (both described here) are not applicable. I used my own network classes to simulate a ping (just send a packet and echo it back), and it works fine except for one thing: it has no choice but to take the client''s framerate into account. So if a client''s FPS dips to 10 for some reason, he''s only updating his sockets every 100ms, so there could be up to 100ms artificially added to his ping because that''s how long it took him to check for and echo the ping packet. Now my network classes work single-threaded, so I suppose the problem would be lessened if the network code was in its own thread updating at a fixed rate. But, even then, if you update it 30 times a second, that''s still up to 33ms added to the real ping. And, I don''t want to redesign my network code just for better ping support. Is there some winsock or win32 functionality I''m not aware of to help you ping remote machines in a non-blocking way? Or if anyone has other suggestions, feel free... Thanks
Well, try using threads.

That''s what i do.
have one thread taking care of the networking and another taking care about the grapichs.


/Regards Niklas Lönn
Advertisement
not a windows guru but what about WSAASyncSelect or whatever its called?

- Damage Inc.
Check http://www.cs.cf.ac.uk/Dave/C/node29.html for info about threads.

/regards Niklas Lönn.


Sorry that was for UNIX.

try this.

If you need to know how the functions work, try check MSDN.

Here''s the code:

#include <stdio.h>
#include <windows.h>

void mythread();

void main()
{
DWORD mp; //Our Thread reference.
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&mythread,0,0,&mp);
while(1)
{
printf("B";
}
}

void mythread()
{
while(1)
{
printf("A";
}
}



/regards Niklas
Damn forum.

here''s the code.


Here''s the code:
#include <stdio.h>#include <windows.h>void mythread();void main(){	DWORD mp; //Our Thread reference.	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&mythread,0,0,&mp);	while(1)	{		printf("B";	}}void mythread(){	while(1)	{		printf("A";	}}


/regards Niklas

This topic is closed to new replies.

Advertisement