Yacoby
Yacoby

Reputation: 55445

Asynchronous Bidirectional RPC

I am looking for a RPC library in Java or Python (Python is preferred) that uses TCP. It should support:

Any recommendations? I have looked a things like bjsonrpc which seemed to be the right sort of thing however it didn't seem possible for the server to identify which connections; so if a user has identified himself/herself and a request comes in from another user to send a message to that user it doesn't expose that users connection so we can send the message.

Upvotes: 5

Views: 5520

Answers (4)

Versile
Versile

Reputation: 308

I am involved in developing Versile Python (VPy) which provides the capabilities you are requesting. It is currently available as development releases intended primarily for testing, however you may want to check it out.

Regarding identifying users you can configure remote methods to receive a context object which enables the method to receive information about an authenticated user, using a syntax similar to this draft code.

from versile.quick import *

@doc
class MessageBox(VExternal):
    """Dispatches IM messages."""
    @publish(show=True, doc=True, ctx=True)
    def send_message(self, msg, ctx=None):
        """Sends a message to the message box"""
        if ctx.identity is None:
            raise VException('No authenticated user')
        else:
            # do something ...
            pass

Upvotes: 1

deavidsedice
deavidsedice

Reputation: 381

i'm the author of bjsonrpc. I'm sure it's possible to do what you want with it.

Some things maybe are poorly documented or maybe some examples are needed.

But, in short, Handlers can store internal states (like authenticated or not, or maybe username). From any handler you can access the "Connection" class, which has the socket itself.

Seems you want something like a chat as an example. I did something similar in the past. I'll try to add a chat example for a new release.

Internal states are explained here: http://packages.python.org/bjsonrpc/tutorial1/index.html#stateful-server

They should be used for authentication (but no standard auth method is provided yet).

On how to reach the connection class from the handler, that isn't documented yet (sorry), but it is used sometimes in the examples inside the source code. For example, example1-server.py contains this public function:

def gettotal(self):
    self._conn.notify.notify("total")
    return self.value_total

BaseHandler._conn represents the connection for that user. And is exactly the same class you get when you connect:

conn = bjsonrpc.connect(host=host,port=port,handler_factory=MyHandler)

So, you can store the connections for logged users in a global variable, and later call any client method you want to.

Upvotes: 1

rlotun
rlotun

Reputation: 8063

You should definitely check out Twisted. It's an event-based Python networking framework that has an implementation of an event loop (called the "reactor") supporting select, poll, epoll, kqueue and I/O completion ports, and mediates asynchronous calls with objects called Deferreds

As for your RPC requirement, perhaps you should check out Twisted's PB library or AMP.

Upvotes: 6

immortal
immortal

Reputation: 3188

I'm not entirely sure what you meanאt by "Event loop", but you should check out RPyC (Python)

RPyC Project page

Upvotes: 2

Related Questions