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


Python socket.connect方法代碼示例

本文整理匯總了Python中socket.socket.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python socket.connect方法的具體用法?Python socket.connect怎麽用?Python socket.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socket.socket的用法示例。


在下文中一共展示了socket.connect方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _real_connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _real_connect(self, addr, return_errno):
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
                                    self.cert_reqs, self.ssl_version,
                                    self.ca_certs, self.ciphers)
        try:
            socket.connect(self, addr)
            if self.do_handshake_on_connect:
                self.do_handshake()
        except socket_error as e:
            if return_errno:
                return e.errno
            else:
                self._sslobj = None
                raise e
        self._connected = True
        return 0 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:22,代碼來源:ssl.py

示例2: get_server_certificate

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, 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."""

    host, port = addr
    if (ca_certs is not None):
        cert_reqs = CERT_REQUIRED
    else:
        cert_reqs = CERT_NONE
    s = wrap_socket(socket(), ssl_version=ssl_version,
                    cert_reqs=cert_reqs, ca_certs=ca_certs)
    s.connect(addr)
    dercert = s.getpeercert(True)
    s.close()
    return DER_cert_to_PEM_cert(dercert) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:20,代碼來源:ssl.py

示例3: _real_connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname, ssl_sock=self)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                self._connected = True
                if self.do_handshake_on_connect:
                    self.do_handshake()
            return rc
        except (OSError, ValueError):
            self._sslobj = None
            raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:ssl.py

示例4: _real_connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _real_connect(self, addr, return_errno):
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
                                    self.cert_reqs, self.ssl_version,
                                    self.ca_certs, self.ciphers)
        try:
            if return_errno:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                if self.do_handshake_on_connect:
                    self.do_handshake()
                self._connected = True
            return rc
        except socket_error:
            self._sslobj = None
            raise 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:24,代碼來源:ssl.py

示例5: _real_connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        sslobj = self.context._wrap_socket(self, False, self.server_hostname)
        self._sslobj = SSLObject(sslobj, owner=self)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                self._connected = True
                if self.do_handshake_on_connect:
                    self.do_handshake()
            return rc
        except (OSError, ValueError):
            self._sslobj = None
            raise 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:ssl.py

示例6: _real_connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _real_connect(self, addr, connect_ex):
        if self.server_side:
            raise ValueError("can't connect in server-side mode")
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._connected:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
        try:
            if connect_ex:
                rc = socket.connect_ex(self, addr)
            else:
                rc = None
                socket.connect(self, addr)
            if not rc:
                self._connected = True
                if self.do_handshake_on_connect:
                    self.do_handshake()
            return rc
        except (OSError, ValueError):
            self._sslobj = None
            raise 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:24,代碼來源:ssl.py

示例7: connect

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def connect(self, addr):
        """Connects to remote ADDR, and then wraps the connection in
        an SSL channel."""
        self._real_connect(addr, False) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:ssl.py

示例8: _check_connected

# 需要導入模塊: from socket import socket [as 別名]
# 或者: from socket.socket import connect [as 別名]
def _check_connected(self):
        if not self._connected:
            # getpeername() will raise ENOTCONN if the socket is really
            # not connected; note that we can be connected even without
            # _connected being set, e.g. if connect() first returned
            # EAGAIN.
            self.getpeername() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:ssl.py


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