Click here to Skip to main content
Click here to Skip to main content

Voice conference using Multicasting Technique

, 31 Jul 2003
Rate this:
Please Sign up or sign in to vote.
Using multicasting to create a voice conference
<!-- Add the rest of your HTML here -->

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.

//  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)

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
    Create(gport,SOCK_DGRAM, FD_READ)
  • Allow other application to use the port (gport).
    SetSockOpt(SO_REUSEADDR, (void *) &bMultipleApps, sizeof(BOOL), 
               SOL_SOCKET);
  • Join to the multicast group
    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
    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
    ttl=8; //some value > 1    
    send.SetSockOpt(IP_MULTICAST_TTL, &ttl, sizeof(int), IPPROTO_IP)
    
  • Set loopback option to false to prevent loopback (optional)
    //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

Share

About the Author

Nagareshwar
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

 
GeneralHello PinmemberBindu Manohar10-Jan-08 8:02 
Generalproblem during run the the program Pinmembercaptainc/c++18-Nov-07 18:57 
GeneralRe: problem during run the the program PinmemberNagareshwar18-Nov-07 19:24 
GeneralError when run program Pinmembertuongnd8012-Apr-07 22:46 
c:\Downloads\RecordSound\voiceconference_demo\Conference\WriteSound.cpp(13): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall WriteSound::* )(WPARAM,LPARAM)' to 'void (__thiscall CWinThread::* )(WPARAM,LPARAM)'
Mad | :mad:
 
Tuongnd
GeneralRe: Error when run program PinmemberNagareshwar13-Apr-07 7:42 
Generalwave Mixing Pinmembersanjayrvyas3-Feb-06 2:59 
Questionhow to use save Pinmemberdivyajanet12-Dec-05 1:40 
Generalplease help me PinmemberKutti Ra30-Sep-05 17:18 
QuestionWhy +20 and leaving the first 20 chars? PinmemberMPVBRao26-Dec-03 2:55 
Questionhow to start Pinmembercharukala15-Oct-03 15:47 
AnswerRe: how to start Pinmemberdharani31-Oct-03 19:23 
QuestionHow to support a microphone in C#? PinmemberCNWORM22-Aug-03 21:12 
GeneralIF,,,,, i think it is very good solution in the lan Pinmemberwinart6-Aug-03 22:33 
GeneralBandwidth Needed PinmemberAntonDel1-Aug-03 9:57 
GeneralRe: Bandwidth Needed Pinsussnsry(Nagareshwar)1-Aug-03 20:42 
GeneralRe: Bandwidth Needed Pinmembereslea2-Aug-03 22:32 
GeneralRe: Bandwidth Needed Pinmembernsry3-Aug-03 21:01 
GeneralRe: Bandwidth Needed PinmemberAntonDel4-Aug-03 6:28 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 Aug 2003
Article Copyright 2003 by Nagareshwar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid