Dart.PowerTCP.SslSockets Namespace > Udp Class : LeaveMulticastGroup Method |
Leave the specified multicast group for receiving datagrams.
[Visual Basic]
Public Sub LeaveMulticastGroup( _
ByVal groupAddress As IPAddress _
)
[C#]
public void LeaveMulticastGroup(
IPAddress groupAddress
);
[C++]
public: void LeaveMulticastGroup(
IPAddress* groupAddress
)
[C++/CLI]
public:
void LeaveMulticastGroup(
IPAddress^ groupAddress
)
Exception | Description |
---|---|
SocketException | The multicast address is unknown, invalid, or unable to be resolved. |
Use the Udp.LeaveMulticastGroup to leave a multicast group. groupAddress specifies the multicast address group to leave. The host will no longer be able to receive datagrams sent to the multicasted address group. The host will still be listening at the port specified by Open and will still be able to receive datagrams sent to the host's local address/port.
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);
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.