0

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 site, 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.

EDIT.

Server side:

server_amp.py

  1. Starts a reactor: reactor.listenSSL(1234, pf, contextFactory = sslContext,) from within the SATNETServer class.

  2. Assigns protocol, pf, to CredAMPServerFactory class who belongs to module server.py also from within the SATNETServer class.

server.py

  1. Within the class CredAMPServerFactory assigns CredReceiver class to protocol.
  2. Once the connection is established the class SATNETServer is assigned to the protocol.

Client side:

client_amp

  1. Makes a call to the SendMsg method belonging to theSATNETServer class.
Samuel Góngora
  • 141
  • 1
  • 11
  • I see no explicit connection between the title of the question, code snippets, and your actual issue (`AttributeError`). Try to [create a minimal but complete code example that demonstrates the issue](http://stackoverflow.com/help/mcve) – jfs Nov 04 '15 at 15:18
  • The only way I know, at this time, to call a method of the server from the client is using an AMP call, although I put the connector in the protocol where I have the AMP calls, it doesn't recognize the object as existing in the server protocol. That is my question. I will try to create a shorter and concise code to help understanding the problem. – Samuel Góngora Nov 04 '15 at 16:47

0 Answers0