当前位置: 首页>>代码示例>>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;未经允许,请勿转载。