socket.setMulticastTTL(ttl)


设置 IP_MULTICAST_TTL 套接字选项。 虽然 TTL 通常代表 "生存时间",但在此上下文中,它指定了允许数据包通过的 IP 跃点数,特别是对于多播流量。 转发数据包的每个路由器或网关都会递减 TTL。 如果 TTL 被路由器递减为 0,则不会转发。

ttl 参数可以是 0 到 255 之间。 大多数系统上的默认值为 1

如果在未绑定的套接字上调用此方法将抛出 EBADF

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.

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

This method throws EBADF if called on an unbound socket.