def test_stopServer(self): """ You can have many servers running and stop them individually """ h = Hub() h.remote_echo = lambda x: x d = h.startServer(h.getPBServerFactory(), 'tcp:10999') d.addCallback(lambda x: h.startServer(h.getPBServerFactory(), 'tcp:10888')) def killOne(_): return h.stopServer('tcp:10888') d.addCallback(killOne) def testOne(_): # still can connect to the other self.clientPort = None client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999') factory = pb.PBClientFactory() d = client.connect(factory) def saveClient(clientPort): self.clientPort = clientPort d.addCallback(saveClient) d.addCallback(lambda ign: factory.getRootObject()) d.addCallback(lambda obj: obj.callRemote('echo', 'foo')) d.addCallback(lambda res: self.assertEqual(res, 'foo')) d.addCallback(lambda ign: self.clientPort.transport.loseConnection()) d.addCallback(lambda ign: h.stopServer('tcp:10999')) return d d.addCallback(testOne) return d
def test_startServer(self): """ Should call twisted.internet.endpoints.serverFromString and hook that up to the factory """ h = Hub() h.remote_echo = lambda x: x h.startServer(h.getPBServerFactory(), 'tcp:10999') # connect to it self.clientPort = None client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999') factory = pb.PBClientFactory() d = client.connect(factory) def saveClient(clientPort): self.clientPort = clientPort d.addCallback(saveClient) d.addCallback(lambda ign: factory.getRootObject()) d.addCallback(lambda obj: obj.callRemote('echo', 'foo')) d.addCallback(lambda res: self.assertEqual(res, 'foo')) d.addCallback(lambda ign: self.clientPort.transport.loseConnection()) d.addCallback(lambda ign: h.stopServer('tcp:10999')) return d
def test_connect(self): """ You can connect to other servers. This is functionalish """ server = Hub() client = Hub() called = [] client.remoteHubFactory = lambda x: 'foo' client.gotRemoteRoot = called.append server.startServer(server.getPBServerFactory(), 'tcp:10999') def check(r): self.assertEqual(called, ['foo'], "Should have called .gotRemoteRoot with wrapped remote") return r d = client.connect('tcp:host=127.0.0.1:port=10999') d.addCallback(check) d.addCallback(lambda x: client.disconnect( 'tcp:host=127.0.0.1:port=10999')) d.addCallback(lambda x: server.stopServer('tcp:10999')) return d
#!/usr/bin/python from twisted.internet import task from twisted.python import log from twisted.internet import reactor import sys log.startLogging(sys.stdout) from simplebb.hub import Hub h = Hub() h.startServer('tcp:8100') def monitor(): txt = 'builders: %s, outgoing: %s, servers: %s' % ( len(h._builders), len(h._outgoingConns), len(h._servers)) log.msg(txt) t = task.LoopingCall(monitor) t.start(2) def ping(): for b in h._builders: b.getStaticInfo() task.LoopingCall(ping).start(2) reactor.run()
from twisted.internet import reactor, task, utils from twisted.python import log import sys from simplebb.hub import Hub from simplebb.builder import FileBuilder log.startLogging(sys.stdout) fb = FileBuilder('example/projects') h = Hub() h.addBuilder(fb) h.connect('tcp:host=127.0.0.1:port=9222') h.startServer(h.getShellServerFactory(), 'tcp:9224') reactor.run()
from twisted.internet import reactor from twisted.python import log import sys from simplebb.hub import Hub from simplebb.builder import FileBuilder log.startLogging(sys.stdout) fb = FileBuilder('example/projects') h = Hub() h.addBuilder(fb) h.startServer(h.getPBServerFactory(), 'tcp:9222') h.startServer(h.getShellServerFactory(), 'tcp:9223') reactor.run()