Dart.Sockets Namespace > UdpBase Class : LeaveMulticastGroup Method |
'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 )
Exception | Description |
---|---|
System.Net.Sockets.SocketException | The multicast address is unknown, invalid, or unable to be resolved. |
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.
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