1 # You can run this .tac file directly with:
2 # twistd -ny simple.tac
4 from twisted.application import service, internet
5 from twisted.protocols import wire
6 from twisted.internet import protocol
7 from twisted.python import util
9 application = service.Application('test')
10 s = service.IServiceCollection(application)
11 factory = protocol.ServerFactory()
12 factory.protocol = wire.Echo
13 internet.TCPServer(8080, factory).setServiceParent(s)
15 internet.TCPServer(8081, factory).setServiceParent(s)
16 internet.TimerService(5, util.println, "--MARK--").setServiceParent(s)
18 class Foo(protocol.Protocol):
19 def connectionMade(self):
20 self.transport.write('lalala\n')
21 def dataReceived(self, data):
24 factory = protocol.ClientFactory()
25 factory.protocol = Foo
26 internet.TCPClient('localhost', 8081, factory).setServiceParent(s)
28 class FooService(service.Service):
29 def startService(self):
30 service.Service.startService(self)
31 print 'lala, starting'
32 def stopService(self):
33 service.Service.stopService(self)
34 print 'lala, stopping'
35 print self.parent.getServiceNamed(self.name) is self
39 foo.setServiceParent(s)