Your SlideShare is downloading. ×
  • Like
Twisted is easy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Twisted is easy

  • 1,422 views
Published

Slides for lightning talk -- Twisted is easy

Slides for lightning talk -- Twisted is easy

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
1,422
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
7
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Twisted is Easy! Moshe Zadka
  • 2. Do Nothing from twisted.internet import reactor reactor.run()
  • 3. Protocol Parsing from twisted.internet import reactor, protocol class Echo(protocol.Protocol): def dataReceived(self, data): self.transport.write(data) factory = protocol.Factory() factory.protocol = Echo reactor.listenTCP(1033, factory) reactor.run()
  • 4. Web Development from twisted.internet import reactor from twisted.web import resource, server class Resource(resource.Resource): isLeaf = True users = 0 def render_GET(self, request): self.users += 1 return "Welcome user number %d" % self.users reactor.listenTCP(1080, server.Site(Resource())) reactor.run()
  • 5. Multi-protocol Servers (Classes) from twisted.internet import reactor, protocol from twisted.web import resource, server class Counter(object): count = 0 def add(self, number): self.count += number class ByteCount(protocol.Protocol): def dataReceived(self, data): self.factory.counter.add(len(data)) class Resource(resource.Resource): isLeaf = True counter = None def render_GET(self, request): return "Received %d bytes" % self.counter.count
  • 6. Multi-protocol Servers (Set-up) factory = protocol.Factory() factory.protocol = ByteCount factory.counter = Counter() resource = Resource() resource.counter = factory.counter reactor.listenTCP(1033, factory) reactor.listenTCP(1080, server.Site(resource)) reactor.run()