Socket.DontFragment Socket.DontFragment Socket.DontFragment Socket.DontFragment Property

定义

获取或设置 Boolean 值,该值指定 Socket 是否允许将 Internet 协议 (IP) 数据报分段。Gets or sets a Boolean value that specifies whether the Socket allows Internet Protocol (IP) datagrams to be fragmented.

public:
 property bool DontFragment { bool get(); void set(bool value); };
public bool DontFragment { get; set; }
member this.DontFragment : bool with get, set
Public Property DontFragment As Boolean

属性值

如果 Socket 允许数据报分段,则为 true;否则为 falsetrue if the Socket allows datagram fragmentation; otherwise, false. 默认值为 trueThe default is true.

异常

只有对于在 InterNetworkInterNetworkV6 族中的套接字,才可以设置此属性。This property can be set only for sockets in the InterNetwork or InterNetworkV6 families.

尝试访问套接字时出错。An error occurred when attempting to access the socket.

示例

下面的代码示例演示如何将DontFragment属性。The following code example demonstrates the use of the DontFragment property.

static void ConfigureUdpSocket(Socket^ udpSocket)
{

    // Set the Don't Fragment flag.
    udpSocket->DontFragment = true;
     
    // Enable broadcast.
    udpSocket->EnableBroadcast = true;
     
    // Disable multicast loopback.
    udpSocket->MulticastLoopback = false;
    Console::WriteLine("Udp Socket configured:");
    Console::WriteLine("  DontFragment {0}", 
        udpSocket->DontFragment);
    Console::WriteLine("  EnableBroadcast {0}", 
        udpSocket->EnableBroadcast);
    Console::WriteLine("  MulticastLoopback {0}", 
        udpSocket->MulticastLoopback);
}
      static void ConfigureUdpSocket(Socket udpSocket)
{
	// set the Don't Fragment flag.
	udpSocket.DontFragment = true;
	// Enable broadcast.
	udpSocket.EnableBroadcast = true;

	// Disable multicast loopback.
	udpSocket.MulticastLoopback = false;

	Console.WriteLine("Udp Socket configured:");
	Console.WriteLine("  DontFragment {0}", 
                                              udpSocket.DontFragment);
	Console.WriteLine("  EnableBroadcast {0}", 
                                              udpSocket.EnableBroadcast);
	Console.WriteLine("  MulticastLoopback {0}", 
                                              udpSocket.MulticastLoopback);
}

注解

其大小超过最大传输单元 (MTU) 的传输媒体时,数据报要求碎片。Datagrams require fragmentation when their size exceeds the Maximum Transfer Unit (MTU) of the transmission medium. 数据报可能通过发送主机 (所有 Internet 协议版本) 或中间路由器 (Internet 协议版本 4 仅) 分段。Datagrams may be fragmented by the sending host (all Internet Protocol versions) or an intermediate router (Internet Protocol Version 4 only). 如果必须碎片数据报,和DontFragment选项设置、 数据报将被放弃,并且 Internet 控制消息协议 (ICMP) 错误消息发送回发送方的数据报。If a datagram must be fragmented, and the DontFragment option is set, the datagram is discarded, and an Internet Control Message Protocol (ICMP) error message is sent back to the sender of the datagram.

传输控制协议 (TCP) 套接字上设置此属性不会影响。Setting this property on a Transmission Control Protocol (TCP) socket will have no effect.

适用于