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


Python socket.create_connection方法代码示例

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


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

示例1: connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def connect(self, address, remote_pubkey):
        log.debug('connecting', address=address)
        """
        gevent.socket.create_connection(address, timeout=Timeout, source_address=None)
        Connect to address (a 2-tuple (host, port)) and return the socket object.
        Passing the optional timeout parameter will set the timeout
        getdefaulttimeout() is default
        """
        try:
            connection = create_connection(address, timeout=self.connect_timeout)
        except socket.timeout:
            log.info('connection timeout', address=address, timeout=self.connect_timeout)
            self.errors.add(address, 'connection timeout')
            return False
        except socket.error as e:
            log.info('connection error', errno=e.errno, reason=e.strerror)
            self.errors.add(address, 'connection error')
            return False
        self._start_peer(connection, address, remote_pubkey)
        return True 
开发者ID:heikoheiko,项目名称:pydevp2p,代码行数:22,代码来源:peermanager.py

示例2: send_message_to_slave

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def send_message_to_slave(message, address):
    try:
        payload = generate_msgpack_message_payload(message)
    except TypeError:
        logger.exception('Failed encoding message %s as msgpack', message)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False

    pretty_address = '%s:%s' % address
    message_id = message.get('message_id', '?')
    try:
        s = socket.create_connection(address)
        s.send(payload)
        sender_resp = msgpack_unpack_msg_from_socket(s)
        s.close()
    except socket.error:
        logging.exception('Failed connecting to %s to send message (ID %s)',
                          pretty_address, message_id)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False

    if sender_resp == 'OK':
        access_logger.info('Successfully passed message (ID %s) to %s for sending',
                           message_id, pretty_address)
        metrics.incr('rpc_message_pass_success_cnt')
        return True
    else:
        logger.error('Failed sending message (ID %s) through %s: %s',
                     message_id, pretty_address, sender_resp)
        metrics.incr('rpc_message_pass_fail_cnt')
        return False 
开发者ID:linkedin,项目名称:iris,代码行数:33,代码来源:rpc.py

示例3: connect_socks

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def connect_socks(self, host, port):
        socksconn = None
        try:
            socksconn = socket.create_connection((self.socksip, self.socksport), timeout=self.timeout)
            if not socksutils.basic_handshake_client(socksconn):
                socksconn.close()
            addrtype = socksutils.addr_type(host)
            socksutils.send_request(socksconn, cmd=socksmsg.CONNECT,
                        addrtype=addrtype, dstaddr=host, dstport=port)
            reply = socksutils.read_reply(socksconn)
            if reply.rep != socksmsg.SUCCEEDED:
                log.info("error response %d returned from socks server" % reply.rep)
                socksconn.close()
                return None
            return socksconn
        except Exception, e:
            log.error("[Exception][connect_socks]: %s" % str(e))
            if socksconn:
                socksconn.close()
            return None 
开发者ID:yinghuocho,项目名称:ghttproxy,代码行数:22,代码来源:socks_relay.py

示例4: get_server_certificate

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None):
    """Retrieve the certificate from the server at the specified address,
    and return it as a PEM-encoded string.
    If 'ca_certs' is specified, validate the server cert against it.
    If 'ssl_version' is specified, use it in the connection attempt."""

    _, _ = addr
    if ca_certs is not None:
        cert_reqs = CERT_REQUIRED
    else:
        cert_reqs = CERT_NONE
    context = _create_stdlib_context(ssl_version,
                                     cert_reqs=cert_reqs,
                                     cafile=ca_certs)
    with closing(create_connection(addr)) as sock:
        with closing(context.wrap_socket(sock)) as sslsock:
            dercert = sslsock.getpeercert(True)
    return DER_cert_to_PEM_cert(dercert) 
开发者ID:priyankark,项目名称:PhonePi_SampleServer,代码行数:20,代码来源:_sslgte279.py

示例5: _create_socket

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def _create_socket(self):
        ssl_context = ssl.SSLContext()
        sock = socket.create_connection((self.host, self.port))
        return ssl_context.wrap_socket(sock, server_hostname=self.host) 
开发者ID:naspeh,项目名称:mailur,代码行数:6,代码来源:remote.py

示例6: connect

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def connect(self):
        if self.is_connected:
            return

        try:
            self.socket = socket.create_connection(
                address=(self.address, self.port),
                timeout=self.timeout,
            )

        except socket.error as error:
            six.raise_from(NSQSocketError(*error.args), error) 
开发者ID:wtolson,项目名称:gnsq,代码行数:14,代码来源:stream.py

示例7: _create_socket

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def _create_socket(self):
        return socket.create_connection((self.host, self.port)) 
开发者ID:naspeh,项目名称:mailur,代码行数:4,代码来源:local.py

示例8: handle

# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import create_connection [as 别名]
def handle(self, source, address):  # pylint:disable=method-hidden
        log('%s:%s accepted', *address[:2])
        try:
            dest = create_connection(self.dest)
        except IOError as ex:
            log('%s:%s failed to connect to %s:%s: %s', address[
                0], address[1], self.dest[0], self.dest[1], ex)
            return
        forwarders = (gevent.spawn(forward, source, dest, self),
                      gevent.spawn(forward, dest, source, self))
        gevent.joinall(forwarders) 
开发者ID:dongweiming,项目名称:web_develop,代码行数:13,代码来源:portforwarder.py


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