本文整理匯總了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.