本文整理汇总了Python中twisted.internet.protocol.ClientFactory.forProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory.forProtocol方法的具体用法?Python ClientFactory.forProtocol怎么用?Python ClientFactory.forProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ClientFactory
的用法示例。
在下文中一共展示了ClientFactory.forProtocol方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _initClient
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import forProtocol [as 别名]
def _initClient(self, clientConnString):
"""
Инициализация клиента
:type clientConnString: str строка подключения для clientFromString
:return : defer.Deferred с аргументом self.clientProtocol
"""
clientEndpoint = clientFromString(self.reactor, clientConnString)
saveProtocol = lambda p: save(self, 'clientProtocol', p) # given protocol
self.clientFactory = ClientFactory.forProtocol(lambda: AMP(locator=self.locator))
return clientEndpoint.connect(self.clientFactory).addCallback(saveProtocol).addCallback(self.setClientProtocol)
示例2: _connectClient
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import forProtocol [as 别名]
def _connectClient(self, d2):
"""
Подключиться к серверу
:param d2: defer.Deferred вызываемый при connectionLost
:return: defer.Deferred с результатом подключения (инициализированный протокол ClientProtocolStub)
"""
factory = ClientFactory.forProtocol(ClientProtocolStub)
factory.onConnectionLost = d2
return clientFromString(self.reactor, b"tcp:host=localhost:port={0}".format(self.serverPort.getHost().port)) \
.connect(factory)
示例3: listening
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import forProtocol [as 别名]
def listening(port):
msg("Listening on %r" % (port.getHost(),))
endpoint = self.endpoints.client(reactor, port.getHost())
client = endpoint.connect(
ClientFactory.forProtocol(lambda: clientProtocol))
def disconnect(proto):
msg("About to disconnect %r" % (proto,))
proto.transport.loseConnection()
client.addCallback(disconnect)
client.addErrback(lostConnectionDeferred.errback)
return lostConnectionDeferred
示例4: setUp
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import forProtocol [as 别名]
def setUp(self):
self.client_factory = ClientFactory.forProtocol(DummyClientProtocol)
self.server_factory = ServerFactory.forProtocol(DummyServerProtocol)
示例5: main
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import forProtocol [as 别名]
def main(reactor):
ep = UNIXClientEndpoint(reactor, '/var/run/postgresql/.s.PGSQL.5432')
fact = ClientFactory.forProtocol(PostgresProtocol)
proto = yield ep.connect(fact)
# for i in range(5000):
res = yield proto.runQuery('SELECT * from entries limit 5')