Click here to Skip to main content
13,201,452 members (72,249 online)
Click here to Skip to main content
Add your own
alternative version


492 bookmarked
Posted 15 Aug 2000

Network Development Kit 2.0

, 29 Dec 2006
Rate this:
Please Sign up or sign in to vote.
Network Development Kit is a set of simple classes for a client-server architecture.

NDK Standard

NDK in an Extension DLL


With the success of NDK 1.0, I decided to improve the functionality. NDK represents Network Development Kit. The NDK is a set of classes that implements a client/server architecture. The NDK hides all the complexity of the connection, sending, and receiving of data over a network. You only have to deal with three classes: CNDKServer, CNDKClient, and CNDKMessage. With just a few methods to override, you obtain a complete robust client/server application. The NDK is based on the class CSocket from MFC, so you can run your application on a local network or on the Internet without any change. To easily understand the integration of the NDK in an application, you'll find at the end of this article a complete chat application.


CNDKServer: Server side of the client/server architecture


  • BOOL IsStarted() const;
  • long GetPort() const;
  • long GetNbUsers() const;
  • void GetUserIds(CLongArray& alIds) const;


  • BOOL StartListening(long lPort);
  • void Stop();
  • BOOL SendMessageToUser(long lUserId, CNDKMessage& message);
  • BOOL SendMessageToAllUsers(CNDKMessage& message);
  • BOOL SendMessageToSomeUsers(const CLongArray& alUserIds, CNDKMessage& message);
  • BOOL SendMessageToAllUsersExceptFor(long lUserId, CNDKMessage& message);
  • BOOL SendMessageToAllUsersExceptFor(const CLongArray& alUserIds, CNDKMessage& message);
  • BOOL DisconnectUser(long lUserId);
  • void DisconnectAllUsers();
  • BOOL PingUser(long lUserId);
  • void PingAllUsers();


  • virtual BOOL OnIsConnectionAccepted() = 0;
  • virtual void OnConnect(long lUserId) = 0;
  • virtual void OnMessage(long lUserId, CNDKMessage& message) = 0;
  • virtual void OnDisconnect(long lUserId, NDKServerDisconnection disconnectionType) = 0;
  • virtual void OnPing(long lUserId, long lNbMilliseconds);

CNDKClient: Client side of the client/server architecture


  • BOOL IsConnected() const;
  • BOOL GetIpAndPort(CString& strIp, long& lPort) const;


  • BOOL OpenConnection(const CString& strServerIp, long lPort);
  • void CloseConnection();
  • BOOL SendMessageToServer(CNDKMessage& message);
  • BOOL PingServer();


  • virtual void OnMessage(CNDKMessage& message) = 0;
  • virtual void OnDisconnect(NDKClientDisconnection disconnectionType) = 0;
  • virtual void OnPing(long lNbMilliseconds);

CNDKMessage: Encapsulation of the data that is sent and received by CNDKServer and CNDKClient


  • void SetId(long lId);
  • long GetId() const;
  • int GetNbElements() const;


  • void Add(TYPE typeData);
  • void SetAt(long lIndex, TYPE typeData);
  • void GetAt(long lIndex, TYPE& typeData) const;
  • void GetNext(TYPE& typeData);

Where TYPE can be a UCHAR, char, USHORT, short, UINT, int, long, float, double, CString, or LPVOID data.

What's new in 2.0

  • Hungarian notation is used everywhere
  • CNDKServer notifies automatically CNDKClient when it disconnects and vice-versa
  • CNDKServer has new methods to send a message to a group of users
  • CNDKMessage is easier to use and more robust
  • New methods to ping the server or the client
  • NDK prefix added to all classes to make sure that all class names are unique in your project
  • NDK is standalone or encapsulated in an extension DLL

Client/Server chat

Here are two screenshots of the chat application. Most features of the NDK are shown in both programs.

Client Image

Server Image

Sample code from the chat client

void CChatClientDlg::OnButtonSend() 
   if (UpdateData(TRUE))
      // Create the message with a unique Id: ChatText
      CNDKMessage message(ChatText);

      // Add the data into the message

      // Send the message to the server      

      // Update the UI of the dialog


Sample code from the chat server

void CChatServerDlg::OnMessage(long lUserId, CNDKMessage& message)
   switch (message.GetId())

      case ChatText:
         CString strNickname;

         // Obtain the nickname stored in the map
         m_mapIdsNicknames.Lookup(lUserId, strNickname);

         CString strText;

         // Get the text encapsulated in the message
         message.GetAt(0, strText);

         // Update the UI of the dialog
         AddText(strNickname + _T(": ") + strText);

         // Prepare the message
         message.SetAt(0, strNickname);
         message.SetAt(1, strText);

         // Send the message to all others users
         SendMessageToAllUsersExceptFor(lUserId, message);



  • 17 December 2006
    • Fixed a bug in NDKMessage concerning the length parameter of the GetAt and GetNext methods.
  • 14 October 2005
    • Telnet connections are now disconnected when a connection sends data to the server. Thanks to Stephan Douglas for the solution.
    • Fixed a bug that resolves socket notification since the NDK uses Visual C++ .NET. After a short time, socket notifications were not send anymore.
    • A verification is now made in the serialization of a CNDKMessage to make sure that the message is really a CNDKMessage.
    • Fixed a bug in the method SendMessageToSomeUsers in the NDKServer.cpp.
    • The project is now converted for Visual C++ .NET.


In 2002, the NDK was used in two NASA experiments for the Endeavor mission.


You don't have to be a guru of networking to create a client/server application, you only need to understand the above classes.

If you use the NDK in your project, I would really appreciate to receive an E-mail from you. I plan to make a web page of all programs using the NDK.

I would like to thank Yannick Létourneau who helped me in NDK 1.0.

Good Programming!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Mirego
Canada Canada
My name is Sébastien Lachance.

I love C# developing Windows Phone and Windows 8 applications.

When I’m not in front of a computer, my hobbies include playing bridge, poker and other card games, biking, reading technology news.

You may also be interested in...


Comments and Discussions

GeneralRe: not responding Pin
Member 26088010-Jan-08 15:24
memberMember 26088010-Jan-08 15:24 
GeneralPortability issues Pin
mattf0614-Aug-07 5:51
membermattf0614-Aug-07 5:51 
GeneralRe: Portability issues Pin
Sebastien_Lachance19-Aug-07 9:42
memberSebastien_Lachance19-Aug-07 9:42 
QuestionMessage Map Problem Pin
Sopulee4-Jun-07 21:17
memberSopulee4-Jun-07 21:17 
AnswerRe: Message Map Problem Pin
Sebastien_Lachance10-Jun-07 17:19
memberSebastien_Lachance10-Jun-07 17:19 
QuestionRe: Message Map Problem Pin
Sopulee10-Jun-07 20:57
memberSopulee10-Jun-07 20:57 
AnswerRe: Message Map Problem Pin
HQH12-Jun-07 15:50
memberHQH12-Jun-07 15:50 
GeneralRe: Message Map Problem Pin
Sopulee14-Jun-07 18:48
memberSopulee14-Jun-07 18:48 
GeneralRe: Message Map Problem Pin
HQH14-Jun-07 19:27
memberHQH14-Jun-07 19:27 
QuestionCNDKMessage & size Pin
Germi Massimo16-May-07 21:55
memberGermi Massimo16-May-07 21:55 
AnswerRe: CNDKMessage & size Pin
Sebastien_Lachance19-May-07 5:41
memberSebastien_Lachance19-May-07 5:41 
QuestionCan this be used in a Service Based app Pin
thomas_tom993-May-07 8:44
memberthomas_tom993-May-07 8:44 
AnswerRe: Can this be used in a Service Based app Pin
Sebastien_Lachance9-May-07 1:30
memberSebastien_Lachance9-May-07 1:30 
QuestionServer Locked Up Pin
valdave18-Apr-07 11:52
membervaldave18-Apr-07 11:52 

Great VC network kit.

There is a problem with the server. Wherever there are two clients connected to the server on a network, if one client is receiving big messages from them and meanwhile if any of the users unplucks his cable from the network, the GUI part of the server gets hanged for a long time. I'm unable to do anything on my screen.

Could you provide me with a solution to this problem on the server side? Also, how come the server (chat) is not multi-threaded?

AnswerRe: Server Locked Up Pin
Sebastien_Lachance18-Apr-07 16:16
memberSebastien_Lachance18-Apr-07 16:16 
GeneralSimple Console App Pin
LuisEstrada21-Mar-07 5:11
memberLuisEstrada21-Mar-07 5:11 
GeneralRe: Simple Console App Pin
Sebastien_Lachance21-Mar-07 5:14
memberSebastien_Lachance21-Mar-07 5:14 
GeneralRe: Simple Console App Pin
LuisEstrada21-Mar-07 6:33
memberLuisEstrada21-Mar-07 6:33 
GeneralNice Article Pin
thomas_tom9916-Mar-07 2:43
memberthomas_tom9916-Mar-07 2:43 
GeneralRe: Nice Article Pin
Sebastien_Lachance16-Mar-07 2:48
memberSebastien_Lachance16-Mar-07 2:48 
GeneralRe: Nice Article Pin
infomaniak20-Jun-07 22:23
memberinfomaniak20-Jun-07 22:23 
GeneralRe: Nice Article Pin
Sebastien_Lachance21-Jun-07 18:33
memberSebastien_Lachance21-Jun-07 18:33 
QuestionCan I use this kit with 2005? Pin
MAP Tiger20-Feb-07 22:42
memberMAP Tiger20-Feb-07 22:42 
QuestionHow can to send an Object as data from client to server Pin
Vis_liner18-Feb-07 9:33
memberVis_liner18-Feb-07 9:33 
AnswerRe: How can to send an Object as data from client to server Pin
Sebastien_Lachance20-Feb-07 14:49
memberSebastien_Lachance20-Feb-07 14:49 
Questionis possible to use NDK for send other files Pin
metal aucard8-Feb-07 20:34
membermetal aucard8-Feb-07 20:34 
AnswerRe: is possible to use NDK for send other files Pin
Sebastien_Lachance9-Feb-07 6:17
memberSebastien_Lachance9-Feb-07 6:17 
GeneralFantastic but I found some Problems Pin
The Yariv2-Jan-07 2:52
memberThe Yariv2-Jan-07 2:52 
GeneralRe: Fantastic but I found some Problems Pin
Sebastien_Lachance2-Jan-07 10:50
memberSebastien_Lachance2-Jan-07 10:50 
GeneralRe: Fantastic but I found some Problems Pin
The Yariv2-Jan-07 21:47
memberThe Yariv2-Jan-07 21:47 
GeneralRe: Fantastic but I found some Problems Pin
Sebastien_Lachance3-Jan-07 2:44
memberSebastien_Lachance3-Jan-07 2:44 
GeneralRe: Fantastic but I found some Problems Pin
The Yariv3-Jan-07 20:23
memberThe Yariv3-Jan-07 20:23 
GeneralRe: Fantastic but I found some Problems Pin
Sebastien_Lachance4-Jan-07 5:08
memberSebastien_Lachance4-Jan-07 5:08 
GeneralFantastic but I found some Problems Pin
The Yariv2-Jan-07 2:50
memberThe Yariv2-Jan-07 2:50 
GeneralAnother compile problem Pin
Joeny30-Dec-06 9:16
memberJoeny30-Dec-06 9:16 
GeneralRe: Another compile problem Pin
Sebastien_Lachance30-Dec-06 17:52
memberSebastien_Lachance30-Dec-06 17:52 
GeneralRe: Another compile problem Pin
Steve Mann6-May-07 20:04
memberSteve Mann6-May-07 20:04 
GeneralRe: Another compile problem Pin
Sebastien_Lachance7-May-07 2:40
memberSebastien_Lachance7-May-07 2:40 
GeneralMultiCasting in SDK Pin
RealiSim28-Dec-06 11:13
memberRealiSim28-Dec-06 11:13 
GeneralCompile Error Pin
vcarinci28-Dec-06 8:32
membervcarinci28-Dec-06 8:32 
GeneralRe: Compile Error Pin
Sbastien Lachance28-Dec-06 8:38
memberSbastien Lachance28-Dec-06 8:38 
GeneralRe: Compile Error Pin
Sbastien Lachance28-Dec-06 10:46
memberSbastien Lachance28-Dec-06 10:46 
QuestionCan be used in services application Pin
Jason( J.Zhang)25-Dec-06 14:33
memberJason( J.Zhang)25-Dec-06 14:33 
GeneralCompile Error: Pin
chungha220-Dec-06 14:49
memberchungha220-Dec-06 14:49 
GeneralRe: Compile Error: Pin
Sbastien Lachance20-Dec-06 19:25
memberSbastien Lachance20-Dec-06 19:25 
Generalconflict:client connected after OnIsConnectionAccepted return false [modified] Pin
WeiMingZhen24-Oct-06 21:10
memberWeiMingZhen24-Oct-06 21:10 
Questionwhen i can see NDK 3.0? Pin
processjudger8815-Oct-06 2:14
memberprocessjudger8815-Oct-06 2:14 
GeneralProblems with x64 platform Pin
naflat20-Sep-06 0:58
membernaflat20-Sep-06 0:58 
GeneralRe: Problems with x64 platform Pin
Epi15-Mar-07 7:03
memberEpi15-Mar-07 7:03 
GeneralProblem with source files Pin
waldermort19-Sep-06 6:51
memberwaldermort19-Sep-06 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171020.1 | Last Updated 29 Dec 2006
Article Copyright 2000 by ArchieCoder
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid