本文整理汇总了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)
示例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