Exemple #1
0
 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
Exemple #2
0
    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