本文整理汇总了Python中twisted.internet.interfaces.IReactorMulticast方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.IReactorMulticast方法的具体用法?Python interfaces.IReactorMulticast怎么用?Python interfaces.IReactorMulticast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.interfaces
的用法示例。
在下文中一共展示了interfaces.IReactorMulticast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _join_multicast_groups
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorMulticast [as 别名]
def _join_multicast_groups(self):
try:
# Need to ensure that the passed-in reactor is, in fact, a "real"
# reactor, and not None, or a mock reactor used in tests.
verifyObject(IReactorMulticast, self.reactor)
except DoesNotImplement:
return
if self.listen_port is None:
self.listen_port = self.reactor.listenMulticast(
self.port, self, interface=self.interface, listenMultiple=True
)
sock = self.transport.getHandle()
if self.loopback:
# This is only necessary for testing.
self.transport.setLoopbackMode(self.loopback)
set_ipv6_multicast_loopback(sock, self.loopback)
self.transport.joinGroup(
BEACON_IPV4_MULTICAST, interface="127.0.0.1"
)
# Loopback interface always has ifindex == 1.
join_ipv6_beacon_group(sock, 1)
for _, ifdata in self.interfaces.items():
# Always try to join the IPv6 group on each interface.
join_ipv6_beacon_group(sock, ifdata["index"])
# Merely joining the group with the default parameters is not
# enough, since we want to join the group on *all* interfaces.
# So we need to join each group using an assigned IPv4 address
# on each Ethernet interface.
for ip in enumerate_ipv4_addresses(ifdata):
self.transport.joinGroup(BEACON_IPV4_MULTICAST, interface=ip)
# Use the first IP address on each interface. Since the
# underlying interface is the same, joining using a
# secondary IP address on the same interface will produce
# an "Address already in use" error.
break