Voice Chat Using Client/Server Architecture

Environment: Visual C++ 6.0, Windows 98/XP

Application Details

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

Technical Details

In Display Class

When the client application starts recording and playing threads created in OnInitDialog() of the Display class.

// Create and Start Recorder Thread
record=new RecordSound(this);

//Create and Start Player Thread
play=new PlaySound1(this);

Thread functions are based on the code by the great person Paul Cheffers (from the CodeGuru site). I am grateful to him for making my dream project become a reality.

PreCreateHeader() of the Display class (from the constructor) creates some buffers for playing wavedata. (This prevents the creation of buffers during runtime…) When the client presses the connect button OnConnect() of the Display class, it connects client to server and displays the userlist and start button. On pressing the start button. recording and playing are started by sending a message to the recording and playing thread (OnStart function).


These messages will activate corresponding functions defined in the message map of the respective thread class.

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

In mysocket class

OnReceive: When data arrives at the client, it will call the Display class’s receive function, which plays the sound by sending message to the PlaySound thread.


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

The PreCreateHeader() function creates buffers for recording data. These are added using the waveInPrepareHeader() and waveInAddBuffer() functions in the OnStartRecording function. (It is called when the 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.

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

Running the Application

First, start the server application (with port number xxx). Then, start a minimum of two clients on any hosts (same or different). I should mention that the server hosts 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; 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 waiting for your doubts and suggestions at nsry2002@yahoo.co.in.

I am grateful to the CodeGuru site for connecting developers….and helping us realise their dreams!!!


Download demo project – 165 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read