I am trying to draw attention to how to get Twisted to execute, due to the lack of a better word, the "interactive" behavior of the client / server.
I managed to collect a couple of Protocol and ClientFactory classes that connect to the service and perform an immediate request / response (see: connectionMade β self.queryStatus). This runs as expected and prints a server response from the Factory class.
Now my problem is that I will have external events that should trigger data transfer, always listening to potential incoming data. But once the reactor.run () loop is started, I'm not sure how the rest of my application is designed to send data.
Since then, I have tried several different approaches, but this is the simplest approach that handled the recv part as described:
class myListenerProtocol(LineReceiver): delimiter = '\n' def connectionMade(self): print("Connected to: %s" % self.transport.getPeer()) self.queryStatus(1) def dataReceived(self, data): print("Receiving Data from %s" % self.transport.getPeer()) ... self.commandReceived(self.myData) def commandReceived(self, myData): self.factory.commandReceived(myData) def connectionLost(self, reason): print("Disconnected.") def queryStatus(self, CommandValue): ... strSend = CommandValue
I suppose this is pretty straight forward, but the countless hours in the numerous examples and documentation left me without a good understanding of how I should deal with this scenario.
source share