diesel / examples / combined.py

The default branch has multiple heads

# vim:ts=4:sw=4:expandtab
'''Combine Client, Server, and Loop, in one crazy app.

Just give it a run and off it goes.

import time
from diesel import Application, Service, Client, Loop, until, call, response

def handle_echo(remote_addr):
    while True:
        message = yield until('\r\n')
        yield "you said: %s" % message

class EchoClient(Client):
    def echo(self, message):
        yield message + '\r\n'
        back = yield until("\r\n")
        yield response(back)

app = Application()

def do_echos():
    client = EchoClient()
    client.connect('localhost', 8000)
    t = time.time()
    for x in xrange(5000):
        msg = "hello, world #%s!" % x
        echo_result = yield client.echo(msg)
        assert echo_result.strip() == "you said: %s" % msg
    print '5000 loops in %.2fs' % (time.time() - t)

app.add_service(Service(handle_echo, port=8000))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.