Click here to Skip to main content
15,121,678 members
Articles / Desktop Programming / Win32
Posted 6 May 2006


79 bookmarked

Chat Client Server

Rate me:
Please Sign up or sign in to vote.
4.21/5 (72 votes)
19 May 2007CPOL1 min read
An implementation of chat client and server with win32 sockets
Sample Image - chat_client_server.jpg - Click to enlarge image


Recently I got myself introduced to socket programming. I read through many books and articles to get an insight into the subject. After learning a bit, I decided to share my knowledge with the world. For this purpose, I created a simple console based chat application. I hope this will be a good reference code for C++ socket programming. I am going to introduce the following concepts to you here.

  • Sockets
  • Multi threading

What is Chat Client Server?

The demo project given along with this article consists of two console-based applications.

Chat Server

Chat server is an application which does the following operations:

  • Listens for incoming calls from clients. Client running in any PC can connect to the server if IP address of the server is known.
  • Listens for messages from all the connected clients.
  • Broadcasts the message from clients to all the clients connected to the server.
  • You can also type-in messages in the server, which will be broadcasted to all the clients.

Chat Client

Chat client does the following things:

  • Sends messages to server as well as to all the connected clients.
  • Views the messages from all the clients and server.

Please download the PDF document to read the rest of the documentation. I have created a PDF because the article consists of 2-3 diagrams.


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


About the Author

Boby Thomas P
Software Developer (Senior) DWS
Australia Australia

Comments and Discussions

QuestionConnecting to server Pin
Member 135619456-Dec-17 9:22
MemberMember 135619456-Dec-17 9:22 
QuestionRun the project Pin
Member 135595355-Dec-17 6:09
MemberMember 135595355-Dec-17 6:09 
QuestionProblem here! Pin
Member 1216378624-Nov-15 5:29
MemberMember 1216378624-Nov-15 5:29 
AnswerRe: Problem here! Pin
Member 1235688228-Feb-16 2:23
MemberMember 1235688228-Feb-16 2:23 
Questionasdf Pin
Member 1127666730-Nov-14 23:58
MemberMember 1127666730-Nov-14 23:58 
GeneralThanks for Sharing Pin
ripon12323-Jun-13 9:57
Memberripon12323-Jun-13 9:57 
QuestionHow would you make it so, you wouldn't receive your own messages? Pin
Member 939065929-Aug-12 1:47
MemberMember 939065929-Aug-12 1:47 
Questionmfc Pin
ZarokovM30-Jul-12 10:56
MemberZarokovM30-Jul-12 10:56 
QuestionClient Server between windows and linux Pin
abhishek3170420-Feb-12 23:02
Memberabhishek3170420-Feb-12 23:02 
GeneralMy vote of 1 Pin
Zeshan Khan15-Jan-12 21:45
MemberZeshan Khan15-Jan-12 21:45 
GeneralRe: My vote of 1 Pin
Member 1116586718-Nov-17 9:48
MemberMember 1116586718-Nov-17 9:48 
GeneralMy vote of 4 Pin
sonu janjua28-Oct-11 3:27
Membersonu janjua28-Oct-11 3:27 
GeneralMy vote of 5 Pin
peejays11-Oct-11 4:57
Memberpeejays11-Oct-11 4:57 
QuestionAfxwin.h not found Pin
Member 808865716-Jul-11 1:51
MemberMember 808865716-Jul-11 1:51 
AnswerRe: Afxwin.h not found Pin
peejays11-Oct-11 4:58
Memberpeejays11-Oct-11 4:58 
GeneralRe: Afxwin.h not found Pin
zuiopvbnm10-Dec-12 6:00
Memberzuiopvbnm10-Dec-12 6:00 
Questionthanks for sharing Pin
ClaireClaire12-Jul-11 21:39
MemberClaireClaire12-Jul-11 21:39 
GeneralQuestion Pin
franchela19-Mar-11 6:12
Memberfranchela19-Mar-11 6:12 
GeneralUnhandled exception Pin
ad_robot7-Jan-11 4:07
Memberad_robot7-Jan-11 4:07 
GeneralMy vote of 4 Pin
Gokulnath00726-Dec-10 21:52
MemberGokulnath00726-Dec-10 21:52 
It fulfilled my requirements what i had been looking for a long time..
Generalc code for chat server........plzzzzzzzzzz...urgent.......... Pin
ankit1011873-Apr-10 4:37
Memberankit1011873-Apr-10 4:37 
Generalplzzzzzzzzzzzz Pin
harsh_amity1-Apr-10 22:10
Memberharsh_amity1-Apr-10 22:10 
QuestionConnectin to my server on remote machine Pin
mehul959526-Mar-10 6:25
Membermehul959526-Mar-10 6:25 
GeneralMy vote of 1 Pin
sathiyapraka7-Jan-10 23:44
Membersathiyapraka7-Jan-10 23:44 
Generalthnx Pin
harshmttl22-Jan-09 8:21
Memberharshmttl22-Jan-09 8:21 

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.