See Also

Udp Class  | Udp Members

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

groupAddress
The System.Net.IPAddress specifying the multicast group address to join.
See Also Languages PowerTCP SSL Sockets for .NET

JoinMulticastGroup Method

Dart.PowerTCP.SslSockets Namespace > Udp Class : JoinMulticastGroup Method

Join the specified multicast group for receiving datagrams.

[Visual Basic]
<DescriptionAttribute("Join the specified multicast group for receiving datagrams.")> Public Sub JoinMulticastGroup( _    ByVal groupAddress As IPAddress _ )
[C#]
[DescriptionAttribute("Join the specified multicast group for receiving datagrams.")] public void JoinMulticastGroup(    IPAddress groupAddress );
[C++]
[DescriptionAttribute("Join the specified multicast group for receiving datagrams.")] public: void JoinMulticastGroup(    IPAddress* groupAddress )
[C++/CLI]
[DescriptionAttribute("Join the specified multicast group for receiving datagrams.")] public: void JoinMulticastGroup(    IPAddress^ groupAddress )

Parameters

groupAddress
The System.Net.IPAddress specifying the multicast group address to join.

Exceptions

ExceptionDescription
SocketExceptionThe multicast address is unknown, invalid, or unable to be resolved.

Remarks

Use the Udp.JoinMulticastGroup method to join a multicast group, useful when you wish for datagrams to be sent to multiple hosts. The host is able to receive all datagrams sent to the specified multicast address and port.

Multicast groups are specified as an IP Address within a specified range of addresses. This group of addresses, also know as class D IP Addresses, are in the range from 224.0.0.0 through 239.255.255.255. In order to receive packets sent to a multicast group (using Udp.Receive), you must first join the group using this method.

Using multicasting over broadcasting reduces the load on hosts that are not interested in the data sent.

Example

The following example demonstrates using multicasting functionality to create a simple chat client.

[Visual Basic] 

' The IPAddress representing the multicast address.
Private add As System.Net.IPAddress = System.Net.IPAddress.Parse("239.255.255.254")

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ' Allocate a socket for listening for datagrams.
   Udp1.Open("MyHost", 1111)

   ' Join the specified multicast group.
   Udp1.JoinMulticastGroup(add)

   ' Begin asynchronously receiving data
   Dim buffer(Udp1.BufferSize) As Byte
   Udp1.BeginReceive(buffer)
End Sub

Private Sub Udp1_EndReceive(ByVal sender As Object, ByVal e As DatagramEventArgs) Handles Udp1.EndReceive
   ' Data received. Display
   txtData.Text += e.Datagram.ToString() + vbCrLF

   ' Begin asynchronously receiving data
   Dim buffer(Udp1.BufferSize) As Byte
   Udp1.BeginReceive(buffer)
End Sub

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
   ' Send button clicked. Send the contents of txtSend.
   Udp1.Send(txtSend.Text, add.ToString(), 1111)
End Sub

Private Sub cmdLeave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLeave.Click
   ' Leave group button clicked. Leave the group.
   Udp1.LeaveMulticastGroup(add)
End Sub

[C#] 


// The IPAddress representing the multicast address.
private System.Net.IPAddress add = System.Net.IPAddress.Parse("239.255.255.254");

private void Form1_Load(object sender, System.EventArgs e)
{
  
// Allocate a socket for listening for datagrams.
  
udp1.Open("MyHost", 1111);

  
// Join the specified multicast group.
  
udp1.JoinMulticastGroup(add);

  
// Begin asynchronously receiving data
  
byte[] buffer = new byte[udp1.BufferSize];
  udp1.BeginReceive(buffer);
}

private void udp1_EndReceive(object sender, DatagramEventArgs e)
{
  
// Data received. Display
  
txtData.Text += e.Datagram.ToString() + "\r\n";
              
  
// Begin asynchronously receiving data
  
byte[] buffer = new byte[udp1.BufferSize];
  udp1.BeginReceive(buffer);
}

private void cmdSend_Click(object sender, System.EventArgs e)
{
  
// Send button clicked. Send the contents of txtSend.
  
udp1.Send(txtSend.Text, add.ToString(), 1111);
}

private void cmdLeave_Click(object sender, System.EventArgs e)
{
  
// Leave group button clicked. Leave the group.
  
udp1.LeaveMulticastGroup(add);
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Udp Class  | Udp Members


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.