If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

NDK 2.0 Enhancements

Here is my modification to NDK class...

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 !