socket.setMulticastTTL(ttl)


设置 IP_MULTICAST_TTL 套接字选项。虽然 TTL 通常表示“生存时间”,但在此上下文中,它指定了数据包允许经过的 IP 跳数,专用于多播流量。每个转发数据包的路由或网关都会减少 TTL。如果 TTL 被路由减少到 0,则该数据包不会被转发。

【Sets the IP_MULTICAST_TTL socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through, specifically for multicast traffic. Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.】

ttl 参数的取值范围可以是 0 到 255。大多数系统上的默认值是 1

【The ttl argument may be between 0 and 255. The default on most systems is 1.】

如果在未绑定的套接字上调用此方法,会抛出 EBADF 异常。

【This method throws EBADF if called on an unbound socket.】