[Twisted-Python] How to call a Twisted reactor from a file different from his module?

Samuel Góngora García s.gongoragarcia at gmail.com
Wed Nov 4 10:00:17 MST 2015


I have a question that could well belong to Twisted or could be directly
related to Python.

My problem, as the other is related to the disconnection process in
Twisted. As I read on this , if I want to I have to perform the following
steps:

1-The server must stop listening.
2-The client connection must disconnect.
3-The server connection must disconnect.

According to what I read on the previous page to make the first step would
have to run the stopListening method.

In the example mentioned in the web all actions are performed in the same
script. Making it easy to access the different variables and methods.

For me I have a server and a client are in different files and different
locations.

I have a function that creates a server, and assigns a protocol and want,
from the client protocol in another file, make an AMP call to a method for
stop the connector.

The call AMP calls the SendMsg command.





































*class TESTServer(protocol.Protocol):    factory = None    sUsername = ""
  credProto = None    bGSuser = None    slot = None"""Here was
uninteresting code."""            #   upwards=self.bGSuser, forwarded=True,
tx_timestamp=iTimestamp,\            #    message=sMsg)
log.msg("self.connector")        log.msg(self.connector)        return
{'bResult': True}    SendMsg.responder(vSendMsg)    def
_testfunction(self):        logger = logging.getLogger('server')
log.startLogging(sys.stdout)        pf = CredAMPServerFactory()
sslContext = ssl.DefaultOpenSSLContextFactory('key/server.pem',\
 'key/public.pem',)        self.connector = reactor.listenSSL(1234, pf,
contextFactory = sslContext,)        log.msg('Server running...')
reactor.run()if __name__ == '__main__':    TESTServer()._testfunction()*
The class CredAMPServerFactory assign the corresponding protocol.










*class CredAMPServerFactory(ServerFactory):    """    Server factory useful
for creating L{CredReceiver} and L{SATNETServer} instances.    This factory
takes care of associating a L{Portal} with the L{CredReceiver}    instances
it creates. If the login is succesfully achieved, a L{SATNETServer}
instance is also created.    """    protocol = CredReceiver*

In the "CredReceiver" class I have a call that assigns the protocol to the
TestServer class. I do this to make calls using the AMP method "Responder".

*        self.protocol = SATNETServer*

My problem is that when I make the call the program responds with an error
indicating that the connector doesn't belong to CredReceiver attribute
object.



*  File "/home/sgongar/Dev/protocol/server_amp.py", line 248, in vSendMsg
  log.msg(self.connector)exceptions.AttributeError: 'CredReceiver' object
has no attribute 'connector'*

How could I do this? Does anyone know of a similar example of that may take
note?

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20151104/81eec059/attachment-0001.html>


More information about the Twisted-Python mailing list