当前位置: 首页>>代码示例>>Python>>正文


Python socket.SIO_KEEPALIVE_VALS属性代码示例

本文整理汇总了Python中socket.SIO_KEEPALIVE_VALS属性的典型用法代码示例。如果您正苦于以下问题:Python socket.SIO_KEEPALIVE_VALS属性的具体用法?Python socket.SIO_KEEPALIVE_VALS怎么用?Python socket.SIO_KEEPALIVE_VALS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socket的用法示例。


在下文中一共展示了socket.SIO_KEEPALIVE_VALS属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def start(self):
		family, socktype, proto, _, sockaddr = socket.getaddrinfo(self.host, self.port, self.family, self.type)[0]

		sock = socket.socket(family, socktype)
		sock.connect(sockaddr)

		if self.nodelay:
			sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

		if self.keepalive:
			sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

		if hasattr(socket, "TCP_KEEPIDLE") and hasattr(socket, "TCP_KEEPINTVL") and hasattr(socket, "TCP_KEEPCNT"):
			sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1 * 60)
			sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30)
			sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)
		elif hasattr(socket, "SIO_KEEPALIVE_VALS"):
			sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 1 * 60 * 1000, 5 * 60 * 1000))

		self.sock = sock
		self.recv_count = 0

		Ksecurity().reset_aes() 
开发者ID:turingsec,项目名称:marsnake,代码行数:25,代码来源:ksocket.py

示例2: set_keep_alive

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def set_keep_alive(self, sock, after_idle_sec=5, interval_sec=60,
                       max_fails=5):
        """
        This function instructs the TCP socket to send a heart beat every n
        seconds to detect dead connections. It's the TCP equivalent of the
        IRC ping-pong protocol and allows for better cleanup / detection
        of dead TCP connections.

        It activates after 1 second (after_idle_sec) of idleness, then sends
        a keepalive ping once every 3 seconds(interval_sec), and closes the
        connection after 5 failed ping (max_fails), or 15 seconds
        """

        # OSX
        if platform.system() == "Darwin":
            # scraped from /usr/include, not exported by python's socket module
            TCP_KEEPALIVE = 0x10
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setsockopt(socket.IPPROTO_TCP, TCP_KEEPALIVE, interval_sec)

        if platform.system() == "Windows":
            sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 10000, 3000))

        if platform.system() == "Linux":
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE,
                            after_idle_sec)
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL,
                            interval_sec)
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails) 
开发者ID:StorjOld,项目名称:pyp2p,代码行数:32,代码来源:sock.py

示例3: create_outbound_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def create_outbound_socket(self, address):
		address = socket.getaddrinfo(*address)[0]
		server_sock = socket.socket(*address[:3])
		if self.timeout:
			server_sock.settimeout(self.timeout)
		server_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
		server_sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 60000, 2000))
		server_sock = ssl.wrap_socket(server_sock)
		return server_sock 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:11,代码来源:transport.py

示例4: test_sock_ioctl

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def test_sock_ioctl(self):
        self.assertTrue(hasattr(socket.socket, 'ioctl'))
        self.assertTrue(hasattr(socket, 'SIO_RCVALL'))
        self.assertTrue(hasattr(socket, 'RCVALL_ON'))
        self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
        self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS'))
        s = socket.socket()
        self.addCleanup(s.close)
        self.assertRaises(ValueError, s.ioctl, -1, None)
        s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_socket.py

示例5: _set_keepalive_times

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def _set_keepalive_times(sock):
            idle_ms = min(_DEFAULT_TCP_IDLE_MS, _MAX_TCP_KEEPIDLE * 1000)
            interval_ms = min(_DEFAULT_TCP_INTERVAL_MS,
                              _MAX_TCP_KEEPINTVL * 1000)
            if (idle_ms < _DEFAULT_TCP_IDLE_MS or
                    interval_ms < _DEFAULT_TCP_INTERVAL_MS):
                sock.ioctl(socket.SIO_KEEPALIVE_VALS,
                           (1, idle_ms, interval_ms)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:pool.py

示例6: connect_to_server

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SIO_KEEPALIVE_VALS [as 别名]
def connect_to_server(self):
        """
        Attempts to connect to the TCP server.

        Raises:
            Exception (OSException): The connection has failed.
        """
        try:
            self.tcp.connect((self.address, TCP_PORT))
            # self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)  # turn on the TCP keepalive
            # self.tcp.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 1000, 1000))  # configure to send a keepalive packet every second
        except Exception:
            self.logger.exception("Unable to connect to host device: IP {0} did not respond.".format(self.address))
            sys.exit(1) 
开发者ID:croningp,项目名称:ChemputerSoftware,代码行数:16,代码来源:Chemputer_Device_API.py


注:本文中的socket.SIO_KEEPALIVE_VALS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。