本文整理汇总了Python中twisted.application.internet.TCPClient方法的典型用法代码示例。如果您正苦于以下问题:Python internet.TCPClient方法的具体用法?Python internet.TCPClient怎么用?Python internet.TCPClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.application.internet
的用法示例。
在下文中一共展示了internet.TCPClient方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testTCP
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def testTCP(self):
s = service.MultiService()
s.startService()
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.TCPServer(0, factory)
t.setServiceParent(s)
num = t._port.getHost().port
factory = protocol.ClientFactory()
factory.d = defer.Deferred()
factory.protocol = Foo
factory.line = None
internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
factory.d.addCallback(self.assertEqual, b'lalala')
factory.d.addCallback(lambda x : s.stopService())
factory.d.addCallback(lambda x : TestEcho.d)
return factory.d
示例2: testPrivileged
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def testPrivileged(self):
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.TCPServer(0, factory)
t.privileged = 1
t.privilegedStartService()
num = t._port.getHost().port
factory = protocol.ClientFactory()
factory.d = defer.Deferred()
factory.protocol = Foo
factory.line = None
c = internet.TCPClient('127.0.0.1', num, factory)
c.startService()
factory.d.addCallback(self.assertEqual, b'lalala')
factory.d.addCallback(lambda x : c.stopService())
factory.d.addCallback(lambda x : t.stopService())
factory.d.addCallback(lambda x : TestEcho.d)
return factory.d
示例3: testTCP
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def testTCP(self):
s = service.MultiService()
s.startService()
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.TCPServer(0, factory)
t.setServiceParent(s)
num = t._port.getHost().port
factory = protocol.ClientFactory()
factory.d = defer.Deferred()
factory.protocol = Foo
factory.line = None
internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
factory.d.addCallback(self.assertEqual, 'lalala')
factory.d.addCallback(lambda x : s.stopService())
factory.d.addCallback(lambda x : TestEcho.d)
return factory.d
示例4: testPrivileged
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def testPrivileged(self):
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.TCPServer(0, factory)
t.privileged = 1
t.privilegedStartService()
num = t._port.getHost().port
factory = protocol.ClientFactory()
factory.d = defer.Deferred()
factory.protocol = Foo
factory.line = None
c = internet.TCPClient('127.0.0.1', num, factory)
c.startService()
factory.d.addCallback(self.assertEqual, 'lalala')
factory.d.addCallback(lambda x : c.stopService())
factory.d.addCallback(lambda x : t.stopService())
factory.d.addCallback(lambda x : TestEcho.d)
return factory.d
示例5: test_reactorParametrizationInClientMultipleStart
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def test_reactorParametrizationInClientMultipleStart(self):
"""
Like L{test_reactorParametrizationInClient}, but stop and restart the
service and check that the given reactor is still used.
"""
reactor = MemoryReactor()
factory = object()
t = internet.TCPClient('127.0.0.1', 1234, factory, reactor=reactor)
t.startService()
self.assertEquals(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
t.stopService()
t.startService()
self.assertEquals(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
示例6: test_client
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def test_client(self):
"""
L{jstrports.client} returns a L{TCPClient} service.
"""
got = jstrports.client("tcp:DOMAIN:65535", "Factory")
self.assertIsInstance(got, TCPClient)
示例7: testConnectionGettingRefused
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def testConnectionGettingRefused(self):
factory = protocol.ServerFactory()
factory.protocol = wire.Echo
t = internet.TCPServer(0, factory)
t.startService()
num = t._port.getHost().port
t.stopService()
d = defer.Deferred()
factory = protocol.ClientFactory()
factory.clientConnectionFailed = lambda *args: d.callback(None)
c = internet.TCPClient('127.0.0.1', num, factory)
c.startService()
return d
示例8: test_reactorParametrizationInClient
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def test_reactorParametrizationInClient(self):
"""
L{internet._AbstractClient} supports a C{reactor} keyword arguments
that can be used to parametrize the reactor used to create new client
connections.
"""
reactor = MemoryReactor()
factory = protocol.ClientFactory()
t = internet.TCPClient('127.0.0.1', 1234, factory, reactor=reactor)
t.startService()
self.assertEqual(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
示例9: test_reactorParametrizationInClient
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def test_reactorParametrizationInClient(self):
"""
L{internet._AbstractClient} supports a C{reactor} keyword arguments
that can be used to parametrize the reactor used to create new client
connections.
"""
reactor = MemoryReactor()
factory = object()
t = internet.TCPClient('127.0.0.1', 1234, factory, reactor=reactor)
t.startService()
self.assertEquals(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
示例10: connectTCP
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def connectTCP(self, host, port, factory, timeout=30, bindAddress=None):
s = internet.TCPClient(host, port, factory, timeout, bindAddress)
s.setServiceParent(self.app)
示例11: __actuallyConnect
# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import TCPClient [as 别名]
def __actuallyConnect(self):
from twisted.application import internet
f = pb.PBClientFactory()
internet.TCPClient(self.host_tx, self.port_tx, f)
creds = UsernamePassword(self.user_tx, self.pswd_tx)
f.login(creds, self.pbReferenceable
).addCallbacks(self.pbCallback, self.couldNotConnect
).setTimeout(30
)