Click here to Skip to main content
15,880,543 members
Articles / Desktop Programming / MFC
Article

Voice conference using Multicasting Technique

Rate me:
Please Sign up or sign in to vote.
4.29/5 (11 votes)
31 Jul 20034 min read 117.4K   5.9K   71   19
Using multicasting to create a voice conference

Introduction

This application uses multicasting technique for audio conference. Interested clients will join the multicast group address (224.0.0.0 - 239.255.255.255). On the LAN when any client sends the voice data to multicast address it will be delivered to all the clients joined to that group by the underlying network automatically. (Even the sending host also receive the copy if it has joined to that address and the application has to handle this situation). If the client only wants to send the data and doesn't want to receive the data then it does not have to join to that group.

On the Internet this feature is possible if routers support multicasting. Otherwise virtual multicasting has to be simulated using mtunneling.(refer details on MBONE-multicast BACKBONE).

The client can select a 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 don't have to worry about the external settings).

Technical Details

Display Class

When the client application started recording and playing threads 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 connects client to 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 thread. (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 message map of respective thread class.

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

Before starting the application the client has to join multicast group using mulitcast group address and port.. this has been done in the CreateSocket(...) function.(called from the Display class).

To receive the messages the client has to join the multicast group. Steps are as follows.

  • Create receiver socket
    C++
    Create(gport,SOCK_DGRAM, FD_READ)
  • Allow other application to use the port (gport).
    C++
    SetSockOpt(SO_REUSEADDR, (void *) &bMultipleApps, sizeof(BOOL), 
               SOL_SOCKET);
  • Join to the multicast group
    C++
    ip_mreq mreq;
    
    mreq.imr_multiaddr.s_addr = inet_addr(gaddr);    //group address
    mreq.imr_interface.s_addr = htons(INADDR_ANY);
    
    setsockopt(m_hSocket,IPPROTO_IP, IP_ADD_MEMBERSHIP, (char FAR *) &mreq,
               sizeof(mreq));

To send the data the steps are as follows:

  • Create Sending socket
    C++
    SOCKADDR_IN hgroup;    
    CAsyncSocket send;
    
    memset(&hgroup, 0, sizeof(hgroup));
    hgroup.sin_family = AF_INET;
    hgroup.sin_addr.s_addr = inet_addr(gaddr);
    hgroup.sin_port = htons((USHORT)gport);
    
    send.Create(0, SOCK_DGRAM, 0);  
  • Set TTL value ...important
    C++
    ttl=8; //some value > 1    
    send.SetSockOpt(IP_MULTICAST_TTL, &ttl, sizeof(int), IPPROTO_IP)
  • Set loopback option to false to prevent loopback (optional)
    C++
    //depends upon underlying protocol..
    //application has to handle loopback(prefered...)    

RecordSound Class

PreCreateHeader() function creates buffers for recording data.These are added using waveInPrepareHeader() and waveInAddBuffer() function 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 Display class itself.

Other classes

MicMute, MicPhone, Mixer are 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

  • LAN : To start the application run the client program and specify the multicast group address (224.2.0.0 ... 239.255.255.255) and port (Specify even number 1024) and type username .Then press the Connect button to connect to the group. If successfully connected to the group the start button will be displayed. On clicking the start button recording will be started. Playing will be started automatically when new data arrives.
  • On the Internet a virtual environment has to be provided using mtunneling (since most routers don't support multicasting..)

Note Any client can send data at any time. Performance depends upon the situation. Developers are free to use their own ideas to improve (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 sites 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

 
Questionunable to run e application Pin
Member 1146146821-Feb-15 17:32
Member 1146146821-Feb-15 17:32 
GeneralHello Pin
Bindu Manohar10-Jan-08 7:02
Bindu Manohar10-Jan-08 7:02 
Generalproblem during run the the program Pin
captainc/c++18-Nov-07 17:57
captainc/c++18-Nov-07 17:57 
GeneralRe: problem during run the the program Pin
Nagareshwar18-Nov-07 18:24
Nagareshwar18-Nov-07 18:24 
GeneralError when run program Pin
tuongnd8012-Apr-07 21:46
tuongnd8012-Apr-07 21:46 
GeneralRe: Error when run program Pin
Nagareshwar13-Apr-07 6:42
Nagareshwar13-Apr-07 6:42 
Generalwave Mixing Pin
sanjayrvyas3-Feb-06 1:59
sanjayrvyas3-Feb-06 1:59 
Questionhow to use save Pin
divyajanet12-Dec-05 0:40
divyajanet12-Dec-05 0:40 
Generalplease help me Pin
Kutti Ra30-Sep-05 16:18
Kutti Ra30-Sep-05 16:18 
QuestionWhy +20 and leaving the first 20 chars? Pin
mpvbrao26-Dec-03 1:55
mpvbrao26-Dec-03 1:55 
Questionhow to start Pin
charukala15-Oct-03 14:47
charukala15-Oct-03 14:47 
AnswerRe: how to start Pin
dharani31-Oct-03 18:23
dharani31-Oct-03 18:23 
QuestionHow to support a microphone in C#? Pin
CNWORM22-Aug-03 20:12
CNWORM22-Aug-03 20:12 
GeneralIF,,,,, i think it is very good solution in the lan Pin
winart6-Aug-03 21:33
winart6-Aug-03 21:33 
GeneralBandwidth Needed Pin
AntonDel1-Aug-03 8:57
AntonDel1-Aug-03 8:57 
GeneralRe: Bandwidth Needed Pin
nsry(Nagareshwar)1-Aug-03 19:42
sussnsry(Nagareshwar)1-Aug-03 19:42 
GeneralRe: Bandwidth Needed Pin
eslea2-Aug-03 21:32
eslea2-Aug-03 21:32 
GeneralRe: Bandwidth Needed Pin
Nagareshwar3-Aug-03 20:01
Nagareshwar3-Aug-03 20:01 
GeneralRe: Bandwidth Needed Pin
AntonDel4-Aug-03 5:28
AntonDel4-Aug-03 5:28 
thanks, i guess that's the coded bytes ..., but the final bandwidth i refer to depends on the RTP header, IP header, packetization and all that stuff. Do you know then what is the bandwidth? (it really differs from the theorical kbps given by a codec)

Thanks,

Anton

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.