Click here to Skip to main content
15,868,340 members
Articles / Desktop Programming / MFC
Article

Voice chat using a client-server architecture

Rate me:
Please Sign up or sign in to vote.
4.77/5 (33 votes)
2 Aug 20033 min read 247.8K   12.1K   84   72
Voice chat networking

Application Details

This software is based on the client - server architecture. Commmunication between the clients is established through the server. Initially server is started. Clients connects to the server host. Server sends the new client list to all the existing clients. The client can select destination user from the user combo box. The software also provides save and play (user can save the sound and play it later). Client also has volume control feature. When client application is started microphone select option (recording) is enabled and microphone mute option is checked (playing) automatically by the program (user doesn't have to worry about the external settings).

Technical Details

Display Class

The recording and playing threads are created in OnInitDialog() of the Display class.
C++
//    Create and Start Recorder Thread
record = new RecordSound(this);
record->CreateThread();
    
//Create and Start Player Thread
play = new PlaySound1(this);
play->CreateThread();

Thread functions are based on the code by great person, Paul Cheffers (from codeguru site). I am grateful to him for making my dream project into reality. PreCreateHeader() of the Display class (from constructor) creates some buffers for playing wavedata. (This prevents creation of buffers during runtime...)

When the client presses the connect button OnConnect() of the Display class the client connects to the server and displays the userlist and start button. On pressing the start button recording and playing is started by sending message to recording and playing threads. (OnStart function)

C++
record->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING, 0, 0);
play->PostThreadMessage(WM_PLAYSOUND_STARTPLAYING, 0, 0);
These messages will activate corresponding functions defined in the message maps of the respective thread classes.

On pressing the stop button recording and playing is stopped by in the same way as above (OnStop Function). It also contains other functions which will be activated on pressing the buttons and some functions are activated from other classes. (mysocket and RecordSound classes).

mysocket class

OnReceive: When data arrives at the client it will call the Display Class's receive function which plays the sound by sending a message to the PlaySound Thread.
C++
play->PostThreadMessage(WM_PLAYSOUND_PLAYBLOCK, 0, (LPARAM) lpHdr);

Message Format

Total length : 2020 bytes
  • 15 : header (destination username or special status)
  • 5 : Length of actual data
  • 2000 : Reserved for actual data.

RecordSound Class

PreCreateHeader()function creates buffers for recording data. These are added using waveInPrepareHeader() and waveInAddBuffer() functions in OnStartRecording function. (Called when Start button is clicked...as explained earlier..)

Playsound1 Class

Contains the functions for starting, playing and stopping wavedata. Buffers are created initially in the Display class itself.

Other classes

MicMute, MicPhone, Mixer are the special classes to add several extra features to Voice - Chat function. Some of the concepts are collected from various developers at the codeguru and codeproject sites. I am grateful to those developers....!!!

Running the Application

First start the server application (with port number xxx). Then start a minimum of 2 clients on any hosts (same or different). Mention server host address and port xxx with username xyz. Then click the connect button. The userlist will be displayed. Select the user and click the start button to start the chat...

Note: Any client can chat with any other client and hence a client can receive data from any number of clients. Performance depends upon the situation. Developers are free to use their own ideas.. (please let me know if you see some new mechanism..)

I am eagerly awaiting your doubts and suggestions at nsry2002@yahoo.co.in.

I am grateful to codeguru and codeproject site for connecting developers....and helping to realise their dreams..!!!

License

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


Written By
Web Developer
India India
Nagareshwar is a security enthusiastic person involved in reverse engineering, vulnerability research, coding security tools etc. He spend most of the time in uncovering the secrets of computer world.

He holds 'Bachelor of Engineering' degree from National Institute of Technology of Karnataka, India. He had professional experience of 2.5 years in Novell. At Novell he was working on various security products including 'Novell Secure Login' and CASA.

For more details visit his website http://securityxploded.com

Comments and Discussions

 
GeneralWant to Compress Pin
booblueboy16-Oct-03 12:42
booblueboy16-Oct-03 12:42 
GeneralRe: Want to Compress Pin
Nagareshwar16-Oct-03 20:46
Nagareshwar16-Oct-03 20:46 
GeneralRe: Want to Compress Pin
booblueboy17-Oct-03 10:01
booblueboy17-Oct-03 10:01 
GeneralA few issues, some may be important Pin
Jim Busse25-Sep-03 11:02
Jim Busse25-Sep-03 11:02 
GeneralRe: A few issues, some may be important Pin
jbeder13-Oct-03 16:36
jbeder13-Oct-03 16:36 
GeneralRe: A few issues, some may be important Pin
Member 81424817-Aug-11 7:36
Member 81424817-Aug-11 7:36 
Generalthanks a lot !!! Pin
dharani12-Sep-03 1:42
dharani12-Sep-03 1:42 
QuestionHow to support a microphone in C# Pin
CNWORM22-Aug-03 20:10
CNWORM22-Aug-03 20:10 
GeneralWhy 2020 Pin
Hing5-Aug-03 0:33
Hing5-Aug-03 0:33 
GeneralRe: Why 2020 Pin
Nagareshwar5-Aug-03 0:41
Nagareshwar5-Aug-03 0:41 
GeneralHi,Bugs Pin
LAT3-Aug-03 8:10
LAT3-Aug-03 8:10 
GeneralRe: Hi,Bugs Pin
Nagareshwar3-Aug-03 18:30
Nagareshwar3-Aug-03 18:30 
GeneralRe: Hi,Bugs Pin
LAT4-Aug-03 9:26
LAT4-Aug-03 9:26 
GeneralGreat article! Pin
eslea2-Aug-03 20:53
eslea2-Aug-03 20:53 
GeneralRe: Great article! Pin
Nagareshwar3-Aug-03 18:32
Nagareshwar3-Aug-03 18:32 
GeneralRe: Great article! Pin
denghby3-Aug-03 21:50
denghby3-Aug-03 21:50 
GeneralRe: Great article! Pin
YuetKent13-Dec-03 4:35
YuetKent13-Dec-03 4:35 
GeneralRe: Great article! Pin
ThatsAlok12-Jan-05 17:47
ThatsAlok12-Jan-05 17:47 

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.