UdpClient.DropMulticastGroup 方法

定义

退出多播组。

重载

DropMulticastGroup(IPAddress)

退出多播组。

DropMulticastGroup(IPAddress, Int32)

退出多播组。

DropMulticastGroup(IPAddress)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

退出多播组。

public:
 void DropMulticastGroup(System::Net::IPAddress ^ multicastAddr);
public void DropMulticastGroup (System.Net.IPAddress multicastAddr);
member this.DropMulticastGroup : System.Net.IPAddress -> unit
Public Sub DropMulticastGroup (multicastAddr As IPAddress)

参数

multicastAddr
IPAddress

要退出的多播组的 IPAddress

例外

已关闭基础 Socket

访问套接字时出错。

IP 地址与定义套接字的寻址方案所用的 AddressFamily 值不相符。

multicastAddrnull

示例

以下示例演示如何通过提供多播地址删除多播组。

// Send data to ClientTarget.
Console::WriteLine( "\nThe ClientOriginator sent:\n" );
Send::OriginatorSendData( clientOriginator, m_ClientTargetdest );

// Receive data from ClientTarget
Ret = Receive::ReceiveUntilStop( clientOriginator );

// Stop the ClientTarget thread
m_t->Abort();

// Abandon the multicast group.
clientOriginator->DropMulticastGroup( m_GrpAddr );

// Send data to ClientTarget.
Console.WriteLine("\nThe ClientOriginator sent:\n");
Send.OriginatorSendData(clientOriginator, m_ClientTargetdest);

// Receive data from ClientTarget
Ret = Receive.ReceiveUntilStop(clientOriginator);

// Stop the ClientTarget thread
m_t.Abort();

// Abandon the multicast group.
clientOriginator.DropMulticastGroup(m_GrpAddr);
' Send data to ClientTarget.
Console.WriteLine(ControlChars.Lf + "The ClientOriginator sent:" + ControlChars.Lf)
Send.OriginatorSendData(clientOriginator, m_ClientTargetdest)

' Receive data from ClientTarget
Ret = Receive.ReceiveUntilStop(clientOriginator)

' Stop the ClientTarget thread
m_t.Abort()

' Abandon the multicast group.
clientOriginator.DropMulticastGroup(m_GrpAddr)

注解

方法DropMulticastGroup从指定的 IPAddress标识的多播组中提取 UdpClient 。 调用 DropMulticastGroup 方法后,基础 Socket 将 Internet 组管理协议 (IGMP) 数据包发送到路由器,从而从多播组中删除路由器。 UdpClient从组退出后,它将不再能够接收发送到该组的数据报。

注意

如果收到 SocketException,请使用 SocketException.ErrorCode 获取特定的错误代码。 获取此代码后,可以参阅 Windows 套接字版本 2 API 错误代码 文档,获取错误的详细说明。

另请参阅

适用于

DropMulticastGroup(IPAddress, Int32)

Source:
UDPClient.cs
Source:
UDPClient.cs
Source:
UDPClient.cs

退出多播组。

public:
 void DropMulticastGroup(System::Net::IPAddress ^ multicastAddr, int ifindex);
public void DropMulticastGroup (System.Net.IPAddress multicastAddr, int ifindex);
member this.DropMulticastGroup : System.Net.IPAddress * int -> unit
Public Sub DropMulticastGroup (multicastAddr As IPAddress, ifindex As Integer)

参数

multicastAddr
IPAddress

要退出的多播组的 IPAddress

ifindex
Int32

要退出的多播组的本地地址。

例外

已关闭基础 Socket

访问套接字时出错。

IP 地址与定义套接字的寻址方案所用的 AddressFamily 值不相符。

multicastAddrnull

示例

下面的代码示例演示如何通过提供多播地址删除多播组。

// Send data to ClientTarget.
Console::WriteLine( "\nThe ClientOriginator sent:\n" );
Send::OriginatorSendData( clientOriginator, m_ClientTargetdest );

// Receive data from ClientTarget
Ret = Receive::ReceiveUntilStop( clientOriginator );

// Stop the ClientTarget thread
m_t->Abort();

// Abandon the multicast group.
clientOriginator->DropMulticastGroup( m_GrpAddr );

// Send data to ClientTarget.
Console.WriteLine("\nThe ClientOriginator sent:\n");
Send.OriginatorSendData(clientOriginator, m_ClientTargetdest);

// Receive data from ClientTarget
Ret = Receive.ReceiveUntilStop(clientOriginator);

// Stop the ClientTarget thread
m_t.Abort();

// Abandon the multicast group.
clientOriginator.DropMulticastGroup(m_GrpAddr);
' Send data to ClientTarget.
Console.WriteLine(ControlChars.Lf + "The ClientOriginator sent:" + ControlChars.Lf)
Send.OriginatorSendData(clientOriginator, m_ClientTargetdest)

' Receive data from ClientTarget
Ret = Receive.ReceiveUntilStop(clientOriginator)

' Stop the ClientTarget thread
m_t.Abort()

' Abandon the multicast group.
clientOriginator.DropMulticastGroup(m_GrpAddr)

注解

方法DropMulticastGroup从指定的 IPAddress标识的多播组中提取 UdpClient 。 调用 DropMulticastGroup 方法后,基础 Socket 将 Internet 组管理协议 (IGMP) 数据包发送到路由器,从而从多播组中删除路由器。 UdpClient从组退出后,它将不再能够接收发送到该组的数据报。

注意

如果收到 , SocketException请使用 SocketException.ErrorCode 属性获取特定的错误代码。 获取此代码后,可以参阅 Windows 套接字版本 2 API 错误代码 文档,获取错误的详细说明。

另请参阅

适用于