NDK 2.0 Enhancements
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: NDK 2.0 Enhancements

Hybrid View

  1. #1
    Join Date
    Dec 2001
    Location
    ROMANIA
    Posts
    30

    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 !
    Attached Files Attached Files
    Last edited by iq0; August 4th, 2003 at 06:28 PM.

  2. #2
    Join Date
    Oct 1999
    Location
    Canada
    Posts
    2

    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?

  3. #3
    Join Date
    Dec 2001
    Location
    ROMANIA
    Posts
    30

    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

  4. #4
    Join Date
    Oct 1999
    Location
    Canada
    Posts
    2

    One little bug

    This is one bug that I known. Replace the following code:

    BOOL CNDKServer::SendMessageToSomeUsers(const CLongArray& alUserIds,
    CNDKMessage& message)
    {
    BOOL bResult = TRUE;

    for (long lUserIndex = 0; lUserIndex < alUserIds.GetSize(); lUserIndex++)
    {
    if (!SendMessageToUser(lUserIndex, message))
    {
    OnDisconnect(lUserIndex, NDKServer_ErrorSendingMessage);
    bResult = FALSE;
    }
    }

    return TRUE;
    }

    with:

    BOOL CNDKServer::SendMessageToSomeUsers(const CLongArray& alUserIds,
    CNDKMessage& message)
    {
    BOOL bResult = TRUE;

    for (long lUserIndex = 0; lUserIndex < alUserIds.GetSize(); lUserIndex++)
    {
    if (!SendMessageToUser(alUserIds[lUserIndex], message))
    {
    OnDisconnect(lUserIndex, NDKServer_ErrorSendingMessage);
    bResult = FALSE;
    }
    }

    return TRUE;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center