~dustin-spy/twisted/dustin

« back to all changes in this revision

Viewing changes to doc/examples/simple.tac

  • Committer: moshez
  • Date: 2003-09-19 08:27:11 UTC
  • Revision ID: vcs-imports@canonical.com-20030919082711-7c4f41d51a909f9d
First stage of application integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
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):
 
17
        print `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
 
29
foo = FooService()
 
30
foo.setName('foo')
 
31
foo.setServiceParent(s)