Click here to Skip to main content
6,292,426 members and growing! (10,150 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

LAN Chat Using Multicating

By Andrews Raj

An article on LAN chat using multicasting.
C#, Windows, .NET, Visual Studio, Dev
Posted:3 Feb 2006
Views:28,465
Bookmarked:17 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
8 votes for this article.
Popularity: 1.31 Rating: 1.45 out of 5
5 votes, 62.5%
1
1 vote, 12.5%
2

3
1 vote, 12.5%
4
1 vote, 12.5%
5

Sample Image - LanChat.jpg

Introduction

This is the Simple Project Will demonstrate the use of multicating in Lan Chat.

Background

"IP Multicasting is a bandwidth-conserving technology that reduces traffic by simultaneously delivering a single stream of information to thousands of corporate recipients and homes."CSCO01.

To transmit a single message to a select group of recipients. A simple example of multicasting is sending an e-mail message to a mailing list. Teleconferencing and videoconferencing also use multicasting, but require more robust protocols and networks.

And Multicasting is Controlled By IGMP ( Internet Group Management Protocol).

Using the code

In LanChat there is only one exe, It Consists of one thread to listen in multicast address throught port 1000. To accept in comming Advertisements from any machine in local Lan. Then it maintains the list of available Users.

And the message send to particular client using Another UDP.

It is very simple and usefull for office environment. 

STEPS

  1. Run LanChat in one machine.
  2. Click Advertise Button. Then you will be listed in all other LanChat's.
  3. And then Send messages...  

Listen:

Socket s = new Socket(AddressFamily.InterNetwork, 
               SocketType.Dgram, ProtocolType.Udp);
IPEndPoint ipep = new IPEndPoint(IPAddress.Any,int.Parse(port));
s.Bind(ipep);
IPAddress ip=IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, 
        SocketOptionName.AddMembership, 
        new MulticastOption(ip,IPAddress.Any));

SEND Message:

try 
{
  IPAddress GroupAddress = IPAddress.Parse(mAddress);
  int GroupPort = port;
  UdpClient sender = new UdpClient();
  IPEndPoint groupEP = new IPEndPoint(GroupAddress,GroupPort);
  byte[] bytes = Encoding.ASCII.GetBytes(message);
  sender.Send(bytes, bytes.Length, groupEP);
  sender.Close();
} 
catch (Exception e) 
{
  MessageBox.Show(e.ToString());
}

Points of Interest

I hope you've enjoyed this little tutorial. In future i will provide you lot more stuffs, And I am expecteding your valuable suggestions.

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

About the Author

Andrews Raj


Member
I am a software engineer working in Blr, india.
working in c++, vc++, mfc, c#.Net, COM/ATL.


Occupation: Software Developer (Senior)
Location: India India

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
QuestionHard coded IP? PinmemberRoonda16:09 5 May '08  
AnswerRe: Hard coded IP? PinmemberAndrews Raj0:41 17 May '08  
GeneralMultiCat Pinmemberrajeev823:58 9 Oct '07  
Generalip multicasting and remote Pinmemberbalazs_hideghety7:13 13 Aug '07  
GeneralUDP MESSAGE PinmemberGigi Carlino7:13 26 Oct '06  
GeneralRe: UDP MESSAGE PinmemberAndrews Raj0:57 28 Dec '06  
Generalhi andrews Pinmembersudharsong20:32 24 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Feb 2006
Editor:
Copyright 2006 by Andrews Raj
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project