Twisted: tcp server with example manufacturer push?

I want to build a simple TCP server using Python and Twisted.

The server starts up and is waiting for a connection - I already have a client application other than python. After connecting, the server starts sending data from a certain interval (for example, 1 second).

The server is reading data from a static file (write at a time), I have to figure out this part.

I assume that I will use a push producer to start pushing data after a client connects.

I have a simple tcp server with a factory in a twisted state, and I can respond to connectionMade / dataReceived and so on, but I can not imagine how to connect the push producer .

Does anyone know any examples showing a push maker with a tcp server in twisted?

+6
python twisted tcpserver
source share
2 answers

How about something simplified type:

thedata = ''' Questa mattina mi son svegliato o bella ciao, bella ciao, bella ciao, ciao, ciao questa mattina mi son svegliato ho trovato l'invasor! '''.splitlines(True) class Push(protocol.Protocol): """This is just about the simplest possible protocol""" def connectionMade(self): for line in thedata: if not line or line.isspace(): continue self.transport.write(line) time.sleep(1.0) self.transport.loseConnection() 

This is hard-coded data, but you say that reading it from a file is not your problem. If you can tell us what happened to this over-simplified push server, perhaps we can offer the best help! -)

+2
source share

Here is a complete example of a push manufacturer. It has been added to twisted svn as an example.

+4
source share

All Articles