It has several enhancements, including :
-user data (like the CListCtrl::SetItemData()) for every connection
-enable or disable the server to send messages to a specific user
-automatic ping timeout handling
-get the size of data within a message
Let me explain every enhancement :
1. User data
This is useful for keeping some data for every user connected (in my case, that's accesses).
There are 2 functions for using this:
DWORD CNDKServer::GetExData(long lUserID);
It returns the extended data for user.
DWORD CNDKServer::SetExData(long lUserID, DWORD dwExData);
Sets the extended data for a user, returning the old value.
That's simple, ha ?
2. Enable or disable the server to send messages to a specific user
This is useful when you you want to avoid that SendMessageToAllUsersExceptFor(), because you must keep a list of your own, and so on.
There are 2 functions for using this:
BOOL CNDKServer::GetSendState(long lUserID);
It returns the send state for user (TRUE if the server can send, and FALSE if the server can't send).
BOOL CNDKServer::SetSendState(long lUserID, BOOL bCanSend);
Sets the send state for a user, returning the old value.
2. Automatic ping timeout handling
This is done with the application help :).
In your application, first call (either for SERVER or CLIENT).
DWORD SetPingTimerInterval(DWORD dwPingTimerInterval);
It returns the old value. I will explain the parameter later.
Then make a timer. And here is the explanation about the parameter.
You know that SetTimer() can be set for about 60 seconds (i think). So if we want a ping at every 120 seconds, what do we do ? We repeat the timer 2 times ! So : the parameter means the number of times before the checking takes place. For example if you set the timer to 60 sec, and the parameter to 1, then the checking takes place at every 60 seconds. If you set the timer at 60 sec, and the parameter at 2 then the checking takes place at every 120 sec. And so on.
Maybe you are asking "what about the checking?". Well in the timer function you must call
int CNDKServer::CheckForDisconnectedUsers();
Function for the server side, returns the number of connections lost. It handles all the timer stuff.
BOOL CNDKClient::CheckForDisconnected();
Function for the client side, returns TRUE if the connection with the server is lost.
That's about all for the ping timeout handling.
3. Get the size of data within a message
This is useful, when you send a file or something like this, and when it is received you want to know how big it is.
This is done by
DWORD CNDKMessage::GetSizeAt(long lIndex = -1);
It retuns the size for a certain item in the message. If you call this function with the parameter set to -1, then it returns the size for the current item.
That's it !
If you have any questions, i will be glad to see if i can answer them :)
Download the file for the sources and a sample project...
Build the project 2 times, changing the #define inside it !
August 6th, 2003, 11:23 PM
ArchieSEB
Very good enhancements
Hi,
All of your items are good helper. If one day I'll made some improvement to the NDK, I'll include some of your stuff.
Thank you,
Sébastien
PS: Would it be possible to see your application?
August 7th, 2003, 09:39 AM
iq0
thank you, but... ?
thank you for your kind words :)
after all, it is you that built the NDK so i think you are the best...
so...there are no bugs ? :) yet ? :)
offcourse you will see my application, but only when it is done :)
i still have to build the help and the site for it...
if you are wondering what it is about, then you i tell you : it is an application for PBX's, i mean for taxing and logging the calls...
maybe you'll even buy it ... :)
thanks again !
iq0
August 17th, 2003, 02:02 PM
ArchieSEB
One little bug
This is one bug that I known. Replace the following code: