PowerTCP Sockets for .NET
LeaveMulticastGroup Method (UdpBase)
Example 




The System.Net.IPAddress specifying the multicast group address to leave.
Leave the specified multicast group for receiving datagrams.
Syntax
'Declaration
 
Public Sub LeaveMulticastGroup( _
   ByVal groupAddress As IPAddress _
) 
'Usage
 
Dim instance As UdpBase
Dim groupAddress As IPAddress
 
instance.LeaveMulticastGroup(groupAddress)
public void LeaveMulticastGroup( 
   IPAddress groupAddress
)
public: void LeaveMulticastGroup( 
   IPAddress* groupAddress
) 
public:
void LeaveMulticastGroup( 
   IPAddress^ groupAddress
) 

Parameters

groupAddress
The System.Net.IPAddress specifying the multicast group address to leave.
Exceptions
ExceptionDescription
System.Net.Sockets.SocketExceptionThe multicast address is unknown, invalid, or unable to be resolved.
Remarks

Use 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 and will still be able to receive datagrams sent to the host's local address/port.

Example
The following example demonstrates joining a multicast group, sending data to it, receiving that data, and leaving the multicast group.
private void button1_Click(object sender, EventArgs e)
{
    udp1.Start(multicastWorker, null);
}

private void multicastWorker(object state)
{
    IPEndPoint groupEndPoint = new IPEndPoint("239.0.0.1", 32000);
    udp1.Open(32000);
    udp1.JoinMulticastGroup(groupEndPoint.Address);
    udp1.Send("hello world!", groupEndPoint);
    byte[] buffer = new byte[1024];
    Datagram datagram = udp1.Receive(buffer);
    //Marshal data to UI for display
    udp1.Marshal(datagram.ToString(), null);
    udp1.LeaveMulticastGroup(groupEndPoint.Address);
    udp1.Close();
}

void udp1_UserState(object sender, UserStateEventArgs e)
{
    textBox1.AppendText(e.Message);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    udp1.Start(AddressOf multicastWorker, Nothing)
End Sub

Private Sub multicastWorker(ByVal state As Object)
    Dim groupEndPoint As New IPEndPoint("239.0.0.1", 32000)
    udp1.Open(32000)
    udp1.JoinMulticastGroup(groupEndPoint.Address)
    udp1.Send("hello world!", groupEndPoint)
    Dim buffer(1023) As Byte
    Dim datagram As Datagram = udp1.Receive(buffer)
    'Marshal data to UI for display
    udp1.Marshal(datagram.ToString(), Nothing)
    udp1.LeaveMulticastGroup(groupEndPoint.Address)
    udp1.Close()
End Sub

Private Sub udp1_UserState(ByVal sender As Object, ByVal e As UserStateEventArgs)
    textBox1.AppendText(e.Message)
End Sub
See Also

Reference

UdpBase Class
UdpBase Members


PowerTCP Sockets for .NET Documentation Version 4.5
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic