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


Python Connection.establish方法代码示例

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


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

示例1: establish

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import establish [as 别名]
 def establish(self, timeout):
     """
     Establishes a server connection.
     Args:
         timeout: this parameter will be ignored.
     Returns:
         Nothing
     """
     Connection.establish(self, timeout)
     # Create and configure the endpoint
     if (not self._useSSL) :
         endpoint = TCP4ServerEndpoint(reactor, self._port)       
     else :
         keyPath = self._certificatesDirectory + "/" + "server.key"
         certificatePath = self._certificatesDirectory + "/" + "server.crt"
         try :
             endpoint = SSL4ServerEndpoint(reactor, self._port, ssl.DefaultOpenSSLContextFactory(keyPath, certificatePath))
         except Exception:
             raise ConnectionException("The key, the certificate or both were not found")          
     # Establish the connection     
     def _registerListeningPort(port):
         self.__listenningPort = port
     def _onError(error):
         self._setError(Connection._prettyPrintTwistedError(error))
     self._deferred = endpoint.listen(self._factory)
     # Configure the deferred object
     self._deferred.addCallback(_registerListeningPort)
     self._deferred.addErrback(_onError)     
开发者ID:lbarriosh,项目名称:cygnus-cloud,代码行数:30,代码来源:serverConnection.py

示例2: establish

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import establish [as 别名]
 def establish(self, timeout=None):
     """
     Tries to establish a client connection.
     Args:
         timeout: the timeout in seconds
     Returns:
         True if the connection was established, and False if it wasn't.
     """
     Connection.establish(self, timeout)
     # Create and configure the endpoint
     if (not self._useSSL) :
         endpoint = TCP4ClientEndpoint(reactor, self.__host, self._port, timeout, None)
     else :
         keyPath = self._certificatesDirectory + "/" + "server.key"
         certificatePath = self._certificatesDirectory + "/" + "server.crt"
         try :
             endpoint = SSL4ClientEndpoint(reactor, self.__host, self._port, 
                 ssl.DefaultOpenSSLContextFactory(keyPath, certificatePath), timeout)
         except Exception:
             raise ConnectionException("The key, the certificate or both were not found")
     # Establish the connection
     self._deferred = endpoint.connect(self._factory)
     self.__working = True
     def _handleError(error):
         self.__working = False
         self._setError(Connection._prettyPrintTwistedError(error))
     def _handleConnection(error):
         self.__working = False
     self._deferred.addCallback(_handleConnection)
     self._deferred.addErrback(_handleError)
     # Wait until it's ready
     while(self.__working) :
         sleep(0.1)
     return self._error == None
开发者ID:lbarriosh,项目名称:cygnus-cloud,代码行数:36,代码来源:clientConnection.py


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