Contenu connexe Similaire à Twisted logic Similaire à Twisted logic (20) Twisted logic4. Google Summer of Code
spend the summer working on
an open source project with a
mentoring organization
6. Server
endpoint = TCP4ServerEndpoint(reactor, 8007)
endpoint.listen(Factory())
Client
endpoint = TCP4ClientEndpoint(reactor,
"localhost", 8007)
endpoint.connect(Factory())
7. class TCP4ServerEndpoint(object):
"""
Implements TCP server endpoint with an IPv4
configuration
"""
...
def __init__(self, reactor, port,
backlog=50, interface=''):
...
def listen(self, protocolFactory):
return defer.execute(
self._reactor.listenTCP,
...)
8. class TCP6ServerEndpoint(object):
"""
Implements TCP server endpoint with an IPv6
configuration
"""
...
def __init__(self, reactor, port,
backlog=50, interface='::'):
...
def listen(self, protocolFactory):
return defer.execute(
self._reactor.listenTCP,
...)
11. class StandardIOEndpoint(object):
"""
A Standard Input/Output endpoint
"""
implements(interfaces.IStreamServerEndpoint)
def __init__(self, reactor):
...
def listen(self, stdioProtocolFactory):
return defer.execute(stdio.StandardIO,
stdioProtocolFactory.buildProtocol(
PipeAddress()))
12. Moral of the story:
Do not get flustered.
Do not overthink..
Forget it's Twisted
13. Moral of the story:
Read the code.
Solve the problem
(write code)
16. class TCP6ClientEndpoint(object):
def __init__(self, reactor, host, port,
timeout=30, bindAddress=None):
...
def connect(self, protocolFactory):
"""
Connect via TCP, once the hostname
resolution is done.
"""
...
17. def _nameResolution(self, host):
"""
Resolve the hostname string into a tuple
containing the host IPv6 address.
"""
...
def _resolvedHostConnect(self, resolvedHost,
protocolFactory):
"""
Connect to the server using the resolved
hostname.
"""
...
19. class SomeState(object):
def __init__(self):
self.values = []
def getValue(self):
return self.values.pop(0)
def addValue(self, value):
self.values.append(value)
20. def foo():
return SomeState()
def bar():
state = foo()
print state.getValue()
25. “It was created by a couple of
dudes who dropped out of
school, and a 16-year-old.
HOW HARD COULD IT BE?”