Skip to main content

ore ore MessagePack RPC

Project description

Yet another MessagePack RPC for Python

samples

demo

#!/usr/bin/env python

port=28080

import tornado_msgpack
dispatcher=tornado_msgpack.Dispatcher()
def add(a, b):
    return a+b
dispatcher.add_handler("add", add)

with tornado_msgpack.ServerLoop("", port, dispatcher.on_message):
    with tornado_msgpack.ClientLoop("localhost", port) as client:
        print(client.call_sync("add", 3, 4))

server

#!/usr/bin/env python

import tornado_msgpack
import tornado

port=18080

# dispatcher
dispatcher=tornado_msgpack.Dispatcher()
def add(a, b):
    return a+b
dispatcher.add_handler("add", add)

# server
server_loop=tornado.ioloop.IOLoop()
server=tornado_msgpack.Server(server_loop, dispatcher.on_message)
server.listen(port)

# blocking...
server_loop.start()

client

#!/usr/bin/env python
import tornado_msgpack
import tornado
import threading

host="127.0.0.1"
port=18080

client_loop=tornado.ioloop.IOLoop()
client_thread=threading.Thread(target=lambda : client_loop.start())

# connecion status
def on_status(session):
    print("status changed: "+session.status)
client=tornado_msgpack.Client(client_loop, on_status)

client.session.connect(host, port)
try:
    client_thread.start()

    # sync
    result=client.call_sync("add", 3, 4)

    # async
    future=client.call_async("add", 5, 6)
    future.join() # wait server respone
    msgpack_rpc=future.message
    result=msgpack_rpc[3]

    # async_with_callback
    def on_receive(msgpack_rpc):
        print(msgpack_rpc)
    future=client.call_async_with_callback(on_receive, "add", 5, 6)
    future.join() # wait server respone

finally:
    client_loop.stop()
    client_thread.join()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tornado_msgpack-0.3.tar.gz (3.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page