Click here to Skip to main content
Licence CPOL
First Posted 6 May 2006
Views 129,504
Downloads 10,540
Bookmarked 59 times

Chat Client Server

By Boby Thomas P | 19 May 2007
An implementation of chat client and server with win32 sockets
5 votes, 8.5%
1
3 votes, 5.1%
2
5 votes, 8.5%
3
11 votes, 18.6%
4
35 votes, 59.3%
5
4.14/5 - 59 votes
4 removed
μ 3.69, σa 2.14 [?]
Sample Image - chat_client_server.jpg - Click to enlarge image

Introduction

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.

License

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



Australia Australia

Member
Check my homepage for more details - Click Here

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionError? PinmemberXHungChung1:33 10 Nov '06  
AnswerRe: Error? PinmemberBoby Thomas P1:37 10 Nov '06  
Generalbehavior after cable break Win2k/ Winxp PinmemberBennet Yee21:13 12 May '06  
Generali have an idea Pinmembernoise@BUPT16:52 9 May '06  
GeneralRe: i have an idea PinmemberBoby Thomas P22:22 9 May '06  
Generalintegration of project Pinmemberdimas7510:54 7 May '06  
GeneralRe: integration of project Pinmembermysterious_caveman11:43 10 Jun '07  
I don't know if i'm understanding you correctly... but if you want to make an application that is event driven just use the tools provided by win32 library. I'd suggest you learn about semaphores and signals then use the following:
 
HANDLE hMyEvent = CreateEvent(NULL, false, false, NULL); // non-signaled state with automatic reset
 
then whenever you want to wait for an event just do the following:
 
DWORD dwReturnValue = WaitForSingleEvent(hMyEvent, INFINITE); // or any time in ms
 
the above will sit and wait until hMyEvent is signaled. To signal it simply do the following:
 
SetEvent(hMyEvent);
 
Once the event is signaled a single thread will proceed and hMyEvent will be reset (to the unsignaled state).
 
I don't know if this is what you're asking, but hope it helps. Sorry it's so rushed. I'm on my way out but I thought I'd just quickly respond to this question off the top of my head because you sound like you're making your life difficult for no reason. Cheers.
Generalthanks Pinmemberraul_sfk1:48 7 May '06  
GeneralRe: thanks PinmemberBoby Thomas P9:56 7 May '06  
Generalinfo required PinmemberSunithaC1:43 7 May '06  
GeneralRe: info required PinmemberBoby Thomas P9:56 7 May '06  
GeneralRe: info required Pinmemberroninttk23:13 9 May '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120210.1 | Last Updated 19 May 2007
Article Copyright 2006 by Boby Thomas P
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid