Click here to Skip to main content
13,191,642 members (59,895 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 17 Jan 2005

Simple CSocket Server Application Support Multiple Clients

Rate this:
Please Sign up or sign in to vote.
For my knowledge this is really simple and effective server application to handle multiple clients simultaniousy and completely independently.

Sample screenshot







This is a really simple application you to all have greate experience in Socket communication. And not only that how to handle worker threads with CSocket objects to support multiple clients. I have spend weeks, to get an idea about this. I searched in lot of sites, papers, books just to do it in simple way as I do now. But I have to say they help me to understand some form of functionalities in VC++. So finally I put all what I understood into one and created this simple infrastructure application to support multiple clients.

Structure of the application

This is a simple dialog based application. I my Dialog window class I have only two buttons to start and stop the server. Once you click on start server It will create Listner thread to listen to the client. So it always wait at the Accept method of the socket. So once client got connected to my server Accept method of the socket will get fire.

Then I am getting the connection object and I'll retreive the handle for that. SOCKET handle is a global variable just to refer it in my client handler thread. Inside the accept, I am creating my second thread to handle my newly created client socket. So all the messages comming from that client is handled inside of this thread.

There are nother 2 global variables just to keep the track of created threads and and handles. this is very useful when you want to shutdown the sockets and terminate the threads.

This is the heart of the program.

UINT ListenThread(LPVOID pParam)
  CieGServerDlg *Dlg= (CieGServerDlg*)pParam;
  CSocket Listen;
  CibCommon iCom;
  int iPort;
  CString strPort;
  iPort = atoi(iCom.readFromRegistry("IEGSERVER","PORT_ID","9000"));
  hServerHandle = Listen.m_hSocket;
      int i=0;
          CSocket * pCSock=
new CSocket();
             hClinetHandle = pCSock->Detach();
             delete pCSock;
             delete pCSock;
      CString strMsg;
      strMsg.Format("Unable to open requested port %s to this server. May be server         running on this port. Please specify another port and start server again.",strPort);
      Dlg->m_bRunServer =
return 0;

I think you will enjoy this, and I am really thank full to the people of code project to have a site like this to help others and to learn.

From this same prgram you can learn how you can write a program to read and write to windows registry. In my CibCommon class, I have implemented this code to use when ever I
I want to write and read from registry.

If you have questions I am relly glad to help you.

Thank you







This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

venura c.p.w. goonatillake
Software Developer (Senior)
Sri Lanka Sri Lanka
I am working as a Tech Lead. I love VC++.
I am trying to get into new technologies coming with VC++ and also in other areas too.

Currently I am working in C# .Net as well...

Now I have sound knowledge in C# as well as in VC++.

You may also be interested in...


Comments and Discussions

Questionwhere isthe client??? Pin
chamilsanjeewa14-Jul-09 17:36
memberchamilsanjeewa14-Jul-09 17:36 
AnswerRe: where isthe client??? Pin
venura c.p.w. goonatillake8-Sep-09 0:22
membervenura c.p.w. goonatillake8-Sep-09 0:22 
GeneralMemory Leak Pin
BigFatBill9-Dec-08 10:03
memberBigFatBill9-Dec-08 10:03 
GeneralRe: Memory Leak Pin
Indiopotent11-Sep-09 11:27
memberIndiopotent11-Sep-09 11:27 
GeneralHi... Pin
chidigam16-Nov-07 1:51
memberchidigam16-Nov-07 1:51 
GeneralRe: Hi... Pin
venura c.p.w. goonatillake16-Nov-07 1:57
membervenura c.p.w. goonatillake16-Nov-07 1:57 
Generalwhere is ieGServer.tlb Pin
Hanna245-Apr-06 6:08
memberHanna245-Apr-06 6:08 
GeneralArchitecture Pin
Anonymous28-Apr-05 7:08
sussAnonymous28-Apr-05 7:08 
GeneralRe: Architecture Pin
JohnyAppleseed18-Aug-06 1:48
memberJohnyAppleseed18-Aug-06 1:48 
GeneralCliHandleList Pin
T-Tung22-Mar-05 19:31
memberT-Tung22-Mar-05 19:31 
GeneralNeed Client Application Pin
PrasadDashputre15-Feb-05 23:40
memberPrasadDashputre15-Feb-05 23:40 
GeneralRe: Need Client Application Pin
T-Tung22-Mar-05 19:32
memberT-Tung22-Mar-05 19:32 
GeneralRe: Need Client Application Pin
electric00926-May-09 22:24
memberelectric00926-May-09 22:24 

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.171017.2 | Last Updated 31 Jan 2005
Article Copyright 2005 by venura c.p.w. goonatillake
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid