sleep

Started by
3 comments, last by hplus0603 14 years, 4 months ago
i`m trying to use raknet and I`m wandering what does the sleep function do, there`s sleep and RakSleep, they probably do the same thing but I`m trying to figure out what exaclty they do. The code to capture network input in the RakN samples is wrapped in a while(true) which I guess puts the system/windows in a comma. Also
while (1)
	{

	// This sleep keeps RakNet responsive
	RakSleep(30);

#ifdef _WIN32
		if (kbhit())
		{
			// Notice what is not here: something to keep our network running.  It's
			// fine to block on gets or anything we want
			// Because the network engine was painstakingly written using threads.
			gets(message);
what does the function kbhit() stand for. Does it check if something (packet) has arrived? [Edited by - Calin on December 7, 2009 9:18:47 AM]

My project`s facebook page is “DreamLand Page”

Advertisement
Raknet runs its own thread. RakSleep(30); tells the raknet thread to take a break.
Sleep() tells your thread to take a break.
kbhit() is Key-Board-Hit, checks if a button has been pressed on your keyboard.
The RakNet function is for RakNet's implementation. For example, it might allow incoming data to still be dequeued but not dispatched (just guessing here -- check the documentation to be sure).

sleep() comes from the standard C library, and does what it says -- suspend the current thread for some number of seconds.

kbhit() is a Microsoft specific C function which checks if a keyboard key has been hit. It's documented on MSDN.
enum Bool { True, False, FileNotFound };
thanks

why does the server waits for keyboard input though. Should't it check and display the incoming packets/text in realtime? That's what it does. When I type in the client console the text shows up in the server console right away without any input from the user.

[Edited by - Calin on December 8, 2009 3:18:16 PM]

My project`s facebook page is “DreamLand Page”

The code itself explains why:

Quote:// Because the network engine was painstakingly written using threads.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement