當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.IP_DROP_MEMBERSHIP屬性代碼示例

本文整理匯總了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 
開發者ID:ros2,項目名稱:ros2cli,代碼行數:24,代碼來源:__init__.py

示例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() 
開發者ID:ros2,項目名稱:ros2cli,代碼行數:12,代碼來源:hello.py

示例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)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:udp.py

示例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)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:udp.py

示例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() 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:29,代碼來源:zeroconf.py

示例6: server_close

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IP_DROP_MEMBERSHIP [as 別名]
def server_close(self):
        self.handle_membership(socket.IP_DROP_MEMBERSHIP) 
開發者ID:enen92,項目名稱:script.tubecast,代碼行數:4,代碼來源:ssdp.py

示例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)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:14,代碼來源:udp.py

示例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)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:13,代碼來源:udp.py

示例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. 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:15,代碼來源:Zeroconf.py


注:本文中的socket.IP_DROP_MEMBERSHIP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。