本文整理汇总了Python中socket.IP_DROP_MEMBERSHIP属性的典型用法代码示例。如果您正苦于以下问题:Python socket.IP_DROP_MEMBERSHIP属性的具体用法?Python socket.IP_DROP_MEMBERSHIP怎么用?Python socket.IP_DROP_MEMBERSHIP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.IP_DROP_MEMBERSHIP属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receive
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def receive(*, group=DEFAULT_GROUP, port=DEFAULT_PORT, timeout=None):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
try:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except AttributeError:
# not available on Windows
pass
s.bind(('', port))
s.settimeout(timeout)
mreq = struct.pack('4sl', socket.inet_aton(group), socket.INADDR_ANY)
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
try:
data, sender_addr = s.recvfrom(4096)
finally:
s.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, mreq)
finally:
s.close()
return data, sender_addr
示例2: shutdown
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def shutdown(self):
if self._is_shutdown:
return
self._is_shutdown = True
self._dummy_socket.sendto(
f'{socket.gethostname()}'.encode('utf-8'), ('127.0.0.1', self._port)
)
self._dummy_socket.close()
self._socket.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, self._mreq)
self._socket.close()
示例3: _joinAddr2
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def _joinAddr2(self, interface, addr, join):
addr = socket.inet_aton(addr)
interface = socket.inet_aton(interface)
if join:
cmd = socket.IP_ADD_MEMBERSHIP
else:
cmd = socket.IP_DROP_MEMBERSHIP
try:
self.socket.setsockopt(socket.IPPROTO_IP, cmd, addr + interface)
except socket.error as e:
return failure.Failure(error.MulticastJoinError(addr, interface,
*e.args))
示例4: _joinAddr2
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def _joinAddr2(self, interface, addr, join):
addr = socket.inet_aton(addr)
interface = socket.inet_aton(interface)
if join:
cmd = socket.IP_ADD_MEMBERSHIP
else:
cmd = socket.IP_DROP_MEMBERSHIP
try:
self.socket.setsockopt(socket.IPPROTO_IP, cmd, addr + interface)
except socket.error as e:
return failure.Failure(error.MulticastJoinError(addr, interface, *e.args))
示例5: close
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def close(self):
"""Ends the background threads, and prevent this instance from
servicing further queries."""
if not self._GLOBAL_DONE:
self._GLOBAL_DONE = True
# remove service listeners
self.remove_all_service_listeners()
self.unregister_all_services()
# shutdown recv socket and thread
self.engine.del_reader(self._listen_socket)
if self.address_family == socket.AF_INET:
self._listen_socket.setsockopt(socket.SOL_IP, socket.IP_DROP_MEMBERSHIP,
socket.inet_aton(_MDNS_ADDR) + socket.inet_aton('0.0.0.0'))
else:
group = socket.inet_pton(socket.AF_INET6,_MDNS_ADDR_IPV6) + self.ifn
self._listen_socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_LEAVE_GROUP,group)
self._listen_socket.close()
self.engine.join()
# shutdown the rest
self.notify_all()
self.reaper.join()
for s in self._respond_sockets:
s.close()
示例6: server_close
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def server_close(self):
self.handle_membership(socket.IP_DROP_MEMBERSHIP)
示例7: _joinAddr2
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def _joinAddr2(self, interface, addr, join):
addr = socket.inet_aton(addr)
interface = socket.inet_aton(interface)
if join:
cmd = socket.IP_ADD_MEMBERSHIP
else:
cmd = socket.IP_DROP_MEMBERSHIP
try:
self.socket.setsockopt(socket.IPPROTO_IP, cmd, addr + interface)
except socket.error, e:
return failure.Failure(error.MulticastJoinError(addr, interface,
*e.args))
示例8: _joinAddr2
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def _joinAddr2(self, interface, addr, join):
addr = socket.inet_aton(addr)
interface = socket.inet_aton(interface)
if join:
cmd = socket.IP_ADD_MEMBERSHIP
else:
cmd = socket.IP_DROP_MEMBERSHIP
try:
self.socket.setsockopt(socket.IPPROTO_IP, cmd, addr + interface)
except socket.error, e:
return failure.Failure(error.MulticastJoinError(addr, interface, *e.args))
示例9: close
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 别名]
def close(self):
"""Ends the background threads, and prevent this instance from
servicing further queries."""
if globals()['_GLOBAL_DONE'] == 0:
globals()['_GLOBAL_DONE'] = 1
self.notifyAll()
self.engine.notify()
self.unregisterAllServices()
self.socket.setsockopt(socket.SOL_IP, socket.IP_DROP_MEMBERSHIP, socket.inet_aton(_MDNS_ADDR) + socket.inet_aton('0.0.0.0'))
self.socket.close()
# Test a few module features, including service registration, service
# query (for Zoe), and service unregistration.