GroupTalk

A Multicast-Based Group Conference Application

Development Environment: Visual C++ 6.0 in Windows98/XP

This is multicasting-based groupchat application in which any number of users can join the group and communicate together. It works on any network that 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 a single host. Broadcasting is sending data to all hosts on the network. Multicasting lies in between these two. It is sending data to a group of hosts. This group is identified by the multicast address.

Every host on the network has an IP Address. An IP Address is divided into five classes. Each class contains a 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 a multicast address. Each group on the network has a unique multicast address associated with it. To create the group, you can choose any address in Class D. It's safer to use any address starting from 225.0.0.0 to 239.255.255.255 because 224.*.*.* are generally used for the router and group management.

Multicasting Program

Multicasting is quite different from unicasting/broadcasting. However, it internally uses a datagram socket for communication. Whenever one of the members sends any message to the group, it will be automatically forwarded to all the members of that group. The important point to be noted here is that you can send a message to any group without joining the group. But, in order to receive messages from the group, you 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);

// Set up 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..!!!
etsockopt(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) ) ;

Because each multicast address represents a group, all hosts who want to communicate together must use the same group address. In the same way, you can use a different multicast address to create a different group.

Group Conference

To implement a group conference, you can use any simple (your own!) protocol and suitable message format. I am using a simple message format.

  1. Membership:
    Type: 5 bytes (JOIN, LEAVE, and so forth terminated with :)
    Username: Rest of the bytes
  2. General Message
    Type: 5 bytes (MESG:)
    Username: 15 bytes (username terminated with 0)
    Length: 5 bytes
    Data: Rest of bytes....

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

Running the Application

To test a 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. To test this application, just run the grouptalk.exe file.

Additional Features

In addition to a group conference application, GroupTalk also demonstrates several useful concepts, such as displaying an icon in the system tray (similar to Yahoo! Messenger), building a customized edit control for trapping an ENTER key event, and running the application at Startup through Registry functions.

For any queries and suggestions, just drop me an e-mail at nsry2002@yahoo.co.in.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds