1
from twisted.application import service, compat, internet
2
from twisted.protocols import wire
3
from twisted.internet import protocol
4
from twisted.python import util
6
application = service.Application('test')
7
s = service.IServiceCollection(application)
8
factory = protocol.ServerFactory()
9
factory.protocol = wire.Echo
10
compat.IOldApplication(s).listenTCP(8080, factory)
11
internet.TCPServer(8081, factory).setServiceParent(s)
12
internet.TimerService(5, util.println, "--MARK--").setServiceParent(s)
13
class Foo(protocol.Protocol):
14
def connectionMade(self):
15
self.transport.write('lalala\n')
16
def dataReceived(self, data):
18
factory = protocol.ClientFactory()
19
factory.protocol = Foo
20
internet.TCPClient('localhost', 8081, factory).setServiceParent(s)
21
class FooService(service.Service):
22
def startService(self):
23
service.Service.startService(self)
24
print 'lala, starting'
25
def stopService(self):
26
service.Service.stopService(self)
27
print 'lala, stopping'
28
print self.parent.getServiceNamed(self.name) is self
31
foo.setServiceParent(s)