[Twisted-Python] Help with TCPServer and listenTCP

I've been looking over some Twisted arcticles over the past day or 2 and havnt found much help on TCPServer, ive seen server/client exampels which use listenTCP and connectTCP, but then i also find one that uses TCPServer. What are the differences between TCPServer and listenTCP, and what are the parameters to TCPServer? I'm trying to write a server/client app which handles a build system, where the build system has x number of builds it needs to handle. Currently each build is done at a set time during the night, so one build might start at 7pm and then the next build might start at 10pm, each build is dependent on other builds. A user can request a build, which will then go to the server and ask if it can start a build and then start with the first dependancy it needs to build. But my main question is about the TCPServer call and how it differs from listenTCP. Cheers. Jimmy. Send instant messages to your online friends http://uk.messenger.yahoo.com

On Fri, 20 Oct 2006 11:56:38 +0100 (BST), James Healey <healeyjames@yahoo.co.uk> wrote:
The parameters to each are the same. The difference is that TCPServer creates an IService provider (which can be added to a service hierarchy and will only create a listening TCP server after its startService method is called), whereas reactor.listenTCP returns a provider of IListeningPort which begins listening almost immediately and does not integrate with the service system.
Are you familiar with buildbot?
But my main question is about the TCPServer call and how it differs from listenTCP.
I hope this clears things up, Jean-Paul

This is my server code....... from twisted.internet import reactor, protocol class Echo(protocol.Protocol): """This is just about the simplest possible protocol""" def dataReceived(self, data): if data == 1: print data def connectionMade(self): print "Client Connected to server" def main(): """This runs the protocol on port 8000""" factory = protocol.ServerFactory() factory.protocol = Echo reactor.listenTCP(8000,factory) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main() And here is my client code..... from twisted.internet import reactor, protocol class EchoClient(protocol.Protocol): """Once connected, send a message, then print the result.""" def connectionMade(self): buildInfo = 1 self.transport.write(buildInfo) def dataReceived(self, data): "As soon as any data is received, write it back." print "Server said:", data self.transport.loseConnection() def connectionLost(self, reason): print "connection lost" class EchoFactory(protocol.ClientFactory): protocol = EchoClient build = 1 def clientConnectionFailed(self, connector, reason): print "Connection failed - goodbye!" reactor.stop() def clientConnectionLost(self, connector, reason): print "Connection lost - goodbye!" reactor.stop() # this connects the protocol to a server runing on port 8000 def main(): f = EchoFactory() reactor.connectTCP("localhost", 8000, f) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main() In this test im trying to send some data when the client makes it's connection, but I get and error when running the client.
Are you familiar with buildbot?
Heard of but never looked at. I'm very new to this Twisted, and quite new to python. Send instant messages to your online friends http://uk.messenger.yahoo.com

On Fri, 20 Oct 2006 16:27:38 +0100 (BST), James Healey <healeyjames@yahoo.co.uk> wrote:
Yes. Only instances of `str' can be written to a transport. If you have non-str data to convey, you need to serialize it somehow.
Are you familiar with buildbot?
Heard of but never looked at.
It is an application which does something much like what you described in your initial email. Jean-Paul

On Fri, 20 Oct 2006 11:56:38 +0100 (BST), James Healey <healeyjames@yahoo.co.uk> wrote:
The parameters to each are the same. The difference is that TCPServer creates an IService provider (which can be added to a service hierarchy and will only create a listening TCP server after its startService method is called), whereas reactor.listenTCP returns a provider of IListeningPort which begins listening almost immediately and does not integrate with the service system.
Are you familiar with buildbot?
But my main question is about the TCPServer call and how it differs from listenTCP.
I hope this clears things up, Jean-Paul

This is my server code....... from twisted.internet import reactor, protocol class Echo(protocol.Protocol): """This is just about the simplest possible protocol""" def dataReceived(self, data): if data == 1: print data def connectionMade(self): print "Client Connected to server" def main(): """This runs the protocol on port 8000""" factory = protocol.ServerFactory() factory.protocol = Echo reactor.listenTCP(8000,factory) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main() And here is my client code..... from twisted.internet import reactor, protocol class EchoClient(protocol.Protocol): """Once connected, send a message, then print the result.""" def connectionMade(self): buildInfo = 1 self.transport.write(buildInfo) def dataReceived(self, data): "As soon as any data is received, write it back." print "Server said:", data self.transport.loseConnection() def connectionLost(self, reason): print "connection lost" class EchoFactory(protocol.ClientFactory): protocol = EchoClient build = 1 def clientConnectionFailed(self, connector, reason): print "Connection failed - goodbye!" reactor.stop() def clientConnectionLost(self, connector, reason): print "Connection lost - goodbye!" reactor.stop() # this connects the protocol to a server runing on port 8000 def main(): f = EchoFactory() reactor.connectTCP("localhost", 8000, f) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main() In this test im trying to send some data when the client makes it's connection, but I get and error when running the client.
Are you familiar with buildbot?
Heard of but never looked at. I'm very new to this Twisted, and quite new to python. Send instant messages to your online friends http://uk.messenger.yahoo.com

On Fri, 20 Oct 2006 16:27:38 +0100 (BST), James Healey <healeyjames@yahoo.co.uk> wrote:
Yes. Only instances of `str' can be written to a transport. If you have non-str data to convey, you need to serialize it somehow.
Are you familiar with buildbot?
Heard of but never looked at.
It is an application which does something much like what you described in your initial email. Jean-Paul
participants (2)
-
James Healey
-
Jean-Paul Calderone