Network Development Kit

Environment: VC6 SP2, Windows 98 and NT
Introduction
Network Development Kit is a set of simple classes for a client-server architecture. It contains 3 main classes : CServerObj, CClientObj and CMessage. With just few method overrides, you have a complete robust client-server application. This architecture is based on CSocket from MFC. You don't have to know how the TCP/IP protocol is implemented to build a client-server application with this NDK. Because the NDK is based on the TCP/IP protocol, your client-server can run on a local network or on the Internet without any change. I provide a simple example of a client-server chat, also you can find another freeware based on the NDK at Net Blitz Homepage (a multiplayer chess program that supports Bughouse).
NDK classes
CServerObj : Server side of client-server architecture.
Public interface
- CServerObj() - Construction.
- virtual ~CServerObj() - Destruction.
- BOOL Init(int port) - Initializes the port on which the server will listen.
- BOOL StartListening() - Effectively start the server.
- void Reset() - Resets the server and disconnect any user that might still be connected.
- void DisconnectUser(ID user) - Forces the disconnection of a user, given its ID.
- BOOL SendMessage(ID user, CMessage &msg) - Sends a message to particular user.
- BOOL SendMessageToAll(CMessage &msg) - Sends a message to every connected user.
- void DisconnectAll() - Disconnects every connected user.
- int GetPort() const - Returns the port
- int GetNbUsers() const - Returns the number of users connected
Protected interface
- virtual BOOL CanConnect() = 0 - Callback method that is called when a user tries to connect to the server.
- virtual void OnConnect(ID user) = 0 - Callback method that is called when a user starts a connection to the server.
- virtual void OnMessage(ID user, CMessage &msg) = 0 - Callback that is called whenever any user sends a message to the server.
- virtual void OnDisconnect(ID user) = 0 - Callback that gets called whenever a user is disconnected for an external reason.
CClientObj : Client side of client-server architecture.
Public interface
- CClientObj() - Construction.
- virtual ~CClientObj() - Destruction.
- BOOL OpenConnection(const CIp &ip, int port) - Opens a connection to the server, given its IP address and the port number.
- void CloseConnection() - Closes an established connection with the server.
- BOOL GetIpAndPort(CIp &ip, UINT &port) const - Retreives the IP address and port number of the client.
- BOOL SendMessage(CMessage &msg) - Sends a message through the network.
Protected interface
- virtual void OnMessage(CMessage &msg) = 0 - Callback method that gets called when a message is received.
- virtual void OnDisconnect(EDisconnectionType reason) = 0 - Callback method that gets called whenever an unexpected disconnection occurs.
CMessage : Data sent and received between CServerObj and CClientObj.
Public interface
- CMessage() - Construction.
- CMessage(int identifier) - Construction with a unique identifier.
- virtual ~CMessage() - Destruction.
- void SetIdentifier(int identifier) - Assigns a unique identifier to each message.
- int GetIdentifier() const - Obtains the identifier of this message.
- int GetNbElements() const - Returns the number of elements in the array of this message.
- void SetElementAt(int index, *Type value*) - Sets a basic element.
- void GetElementAt(int index, *Type &value*) const - Gets a basic element.
Sample usage
// Client side
void CChatClientDlg::OnSendButton()
{
// Retreive the text typed by the user
CString text;
m_inputEdit.GetWindowText(text);
m_inputEdit.SetWindowText("");
// Pack a message with the text to send
CMessage msg(MSG_SEND_TEXT);
msg.SetElementAt(0, text);
// Send the message
((CChatClientApp*)AfxGetApp())->SendMessage(msg);
}
void CChatClientApp::OnMessage(CMessage &msg)
{
switch (msg.GetIdentifier())
{
case MSG_RECEIVE_TEXT:
{
CString text;
// Unpack message elements to retreive the text
msg.GetElementAt(0, text);
((CChatClientDlg*)m_pMainWnd)->AddMessage(text);
}
break;
}
}
// Server side
void CChatServerApp::OnMessage(ID user, CMessage &msg)
{
switch (msg.GetIdentifier())
{
case MSG_SEND_TEXT:
{
CString text;
CString result;
// Unpack message elements to retreive the text
msg.GetElementAt(0, text);
// Format the text to suit our needs
result.Format("[User#%d] %s", user, text);
// Send a text message to everyone
CMessage msgToAll(MSG_RECEIVE_TEXT);
msgToAll.SetElementAt(0, result);
SendMessageToAll(msgToAll);
}
break;
}
}
I hope that this NDK will help you in programming your client-server application.

Comments
Lightweight smart â Nike Loose TR Befit in jump 2013 3 series
Posted by Tufffruntee on 04/22/2013 01:20pmNike Free TR Trim 3 unmistakable features is to use the additional scheme: Nike Self-ruling 5 soles improved bending Scratch; modern tractor imitate making training more focused when; lighter weight, the permeability is stronger, and more trendy shoe designs not only make shoes [url=http://northernroofing.co.uk/roofins.cfm]nike free[/url] more comfortable wearing, barefoot training caress, but also more fashionable appearance. Nike Manumitted TR Fit 3 provides unequalled lateral reliability, you can take the legs in the leg during training. Acrid vamp nobles breathable grate, disgrace soap up's unique lay out can be [url=http://northernroofing.co.uk/roofins.cfm]nike free[/url] seen from stem to stern it. Lightweight, difficult, reduce foam means habituated to through very occasional seams, more amenable, help is stronger. Requirement more help, part of a training utilize, froth come in more parts of the shortage after give, foam loose. Put to use double talk moisture wicking mock materials, vapid on your feet, mitigate maintain feet tiring and comfortable. Phylite [url=http://northernroofing.co.uk/roofins.cfm]nike free run uk[/url] midsole offers lightweight revolt unceasing, special durability and sedate outsole can do to greatly turn the overall load of the shoe. Qianzhang pods on the outsole and heel-shaped Unripened rubber enhances the shoe multi-directional drag on extraordinary surfaces.
Replyuggs selling up-anchor uk
Posted by dwardevlb on 10/28/2012 02:25ameverythingnfl nike jerseys cheaphappenscheap nfl football jerseyscheatedugg stivalimemoryugg salewronggenuine ugg boots ukeverythingcheap uggs boots uksweetugg boots uk salewould
Replytest
Posted by Legacy on 02/13/2003 12:00amOriginally posted by: test
test
Reply
Very nice work!!
Posted by Legacy on 09/10/2002 12:00amOriginally posted by: tich
I tried your demo and it is really nice!!!
But what exactly does the Serialize function when a message should be stored?
It stores the ID of the message and ...?
Is nbElements the size of the message to be sent?
And the for-loop is for storing every single MessageData?
Am I right or can you explain please?
Thanks for the nice application!
tich
ReplyWhere is ".dsw" file?
Posted by Legacy on 09/04/2002 12:00amOriginally posted by: Kevin N
I am trying to open the project but I can't find ".dsw" file. Any help please?
Thanks
Kevin
Replyserver app as W2k service - how to?
Posted by Legacy on 12/03/2001 12:00amOriginally posted by: Andi Wuestner
I like the NDK a lot, it really helped me to create my fist client-server-application.
Just one question: for the server side I'd like to use a W2k service rather than a normal Win32 application. I have found several instructions on how to create a simple W2k service and they worked fine. However, I failed to get them working together with the NDK code. Any idea on how to start this?
Andi
ReplyHow to verify that we have connection ?
Posted by Legacy on 10/07/2001 12:00amOriginally posted by: Oren Farber
Hi
I create CSocket object and use the connect method
Will i test it on win 98 that wasn't connect to a LAN the dail-up dialog appear.
My question is how can I verify that my computer is connected thghout a modem without openning the dail-up dialog?
Oren Farber
ReplyMessage delivering?
Posted by Legacy on 08/24/2001 12:00amOriginally posted by: Pavel Kotrc
Hi, I use your NDK in my project and it's really very helpfull!
But I've encountered a problem - Sometimes when I try to send a message to the server, it is not delivered immediatelly but after a period of time - sometimes it's even more than 1 minute! Actually, I'm testing it now o the local computer - server and client running both on the same machine. I don't know yet, how will it behave on the net, but is there a way, how to "flush" the data, so they are delivered immediately?
Thanks a lot.
ReplyDoes not work under Windows XP
Posted by Legacy on 08/22/2001 12:00amOriginally posted by: Christian Probst
The Init Funktion does not return successfully under Windows XP (Release Candidate 1).
Any idea?
ReplySame Module behaves Client as well as server .
Posted by Legacy on 07/13/2001 12:00amOriginally posted by: Joy Banerjee
Can you please give me the details structure or sample source code of a Module which behaves Client as well as Server ?
ReplyLoading, Please Wait ...