I want to use Twisted to rebuild the communication part of an existing application. This application does send data from the client to the server, only this way round, the server does not send anything.
How do I accomplish this with the event-driven concept of Twisted? I currently use the connectionMade
method of Protocol
, but I don't think this is the right way.
class Send(Protocol):
def connectionMade(self):
while True:
data = queue.get()
self.transport.write(data + "\n")
self.transport.doWrite()
I'm pretty sure, this is not the way to do that. ;-)
Addition:
My problem is, I cannot imaging what event to use for this. I think the connectionMade
event is not the right one, but I will never reach any other event than connectionLost
in my case, because the server does not send anything to the client. Should I change this behavior?