Click here to Skip to main content
15,886,578 members
Articles / Desktop Programming / MFC
Article

GroupTalk - A multicast based group conference application

Rate me:
Please Sign up or sign in to vote.
3.46/5 (15 votes)
17 Jun 20043 min read 61.9K   4.4K   33   5
A multicast based group conference application

Image 1

Introduction

This is multicasting based group chat application in which any number of users can join the group and communicate together. It works on any network which will support multicasting. Multicasting is supported by the wired LAN as well as wireless network. However multicasting is not supported by the internet.

What is multicasting?

Before getting into details of GroupTalk ,we have to be familiar with the term multicasting. Let us start with unicasting and broadcasting. Unicasting is sending data to single host. Broadcasting is sending data to all hosts on the network. Multicasting lies in between these two. It is sending data to group of hosts. This group is identified by the multicast address.

Every host on the network has an IP Address. IP Address is divided into 5 classes. Each class contains specific range of IP addresses.

Class A >> 0.0.0.0 - 126.255.255.255 
Class B >> 128.0.0.0 - 191.255.255.255 
Class C >> 192.0.0.0 - 223.255.255.255 
Class D >> 224.0.0.0 - 239.255.255.255 
Class E >> 240.0.0.0 - 255.255.255.255 

Class D address is called multicast address. Each group on the network has unique multicast address associated with it. In order to create the group you can choose any address in Class D. Its safer to use any address starting from 225.0.0.0 to 239.255.255.255 since 224.*.*.* are generally used for the router and group management.

Multicasting Program

Multicasting is quite different from unicasting /broadcasting. However it internally uses datagram socket for communication. Whenever one of the member sends any message to the group , then it will be automatically forwarded to all the members of that group. Important point to be noted here is that , you can send message to any group without joining the group. But in order to receive the messages from the group , you must have to join that group.

CAsyncSocket send; 
SOCKADDR_IN hgroup; 
ip_mreq mreq; 

int groupport=4000; 
char strgroup[ ]="225.6.7.8"; // Group Address 

// Create datagram socket for receiving group messages 
Create(groupport,SOCK_DGRAM, FD_READ); 

// Setup the multicast group structure... 
memset(&mreq,0,sizeof(ip_mreq)); 
mreq.imr_multiaddr.s_addr = inet_addr(strgroup); /* group addr */ 
mreq.imr_interface.s_addr = htons(INADDR_ANY); /* use default */ 

// Join the group..!!! 
setsockopt(m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
(char far *)&mreq,sizeof(mreq)); 

// Create datagram socket...for sending message to group 
// Set up structure.... 
memset(&hgroup, 0, sizeof(hgroup)); 
hgroup.sin_family = AF_INET; 
hgroup.sin_addr.s_addr = inet_addr(strgroup); // Group Address 
hgroup.sin_port = htons((USHORT)groupport); // Group Port 

// Create datagram socket 
send.Create(0, SOCK_DGRAM, 0); 

// Send the message to group ... 
SendTo(mesg,length,(SOCKADDR*)&hgroup,sizeof(SOCKADDR),0); 

// Receive message from the group... 
ReceiveFrom (buffer, 2000, senderip, senderport); 

// Finally to leave the group.... 
setsockopt(m_hSocket, IPPROTO_IP, IP_DROP_MEMBERSHIP, 
(char far *)&mreq , sizeof(mreq) ) ; 

Since each multicast address represents a group. All hosts who wants to communicate together must use same group address. Sameway you can use different multicast address to create different group.

Group Conference

In order to implement group conference , you can use any simple ( your own!) protocol and suitable message format. I am using simple message format.
  1. Membership
    1. Type : 5 bytes ( JOIN , LEAVE etc terminated with :)
    2. Username : Rest of the bytes
  2. General Message
    1. Type : 5 bytes ( MESG:)
    2. Username : 15 bytes (username terminated with 0)
    3. Length : 5 bytes
    4. Data : Rest of bytes....

As soon as member joins or leaves the group , JOIN or LEVE packet is sent to the group so that all the members can keep track of active members.

Running the application

In order to test multicasting based application , you must be on the multicast enabled network. Conventional LAN and wireless networks support multicasting. You cannot test this application on the single host. In order to test this application just run the grouptalk.exe file.

Additional features

In addition to group conference application , it also demonstrates several useful concepts such as displaying icon in system tray ( similar to yahoo messenger) , building customized edit control for trapping ENTER key event , running application at start up through registry functions. For any queries and suggestions , just drop me an email at nsry2002@yahoo.co.in

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

 
QuestionI can't download the code Pin
1hello215-May-13 5:15
1hello215-May-13 5:15 
QuestionDon't know how to use?? Pin
quocdai22-Dec-07 0:25
quocdai22-Dec-07 0:25 
GeneralWindows Run Key Pin
CodyDaemon5-Feb-06 3:47
CodyDaemon5-Feb-06 3:47 
Questionthe programe does not work Pin
alaa_afeef19-Dec-05 0:04
alaa_afeef19-Dec-05 0:04 
i dont know why
i run the exe file on two computer in a university lab which has a network.
may be the problem in multicast enabled network.
how to enable multicasting
Smile | :)

alaa

-- modified at 6:10 Monday 19th December, 2005
GeneralInteresting! Pin
WREY18-Jun-04 2:36
WREY18-Jun-04 2:36 

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.