Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

pyjamasjsonrpcmongrel2 edited this page · 5 revisions
  1. Pyjamas JSONROC with Mongrel2

There is now an example in the source code along with a jsonrpclib test demonstrating how to create a JSONRPC service with mongrel2 - pyjamas/pyjs/jsonrpc/mongrel2/

In Practice.

First : The Server Side.

You must create a file for serve functions and others.

File :

from pyjs.jsonrpc.mongrel2 import Mongrel2JSONRPCService, jsonremote

from mongrel2 import handler

sender_id = "82209006-86FF-4982-B5EA-D1E29E55D481"

conn = handler.Connection(sender_id, "tcp://", "tcp://")

mongservice = Mongrel2JSONRPCService(conn)
def auth(data):
    return "Connexion reussi."

while True:
    mongservice() # handles one request

You can now run your "new pyjamas json rpc handler".. and go to the next step.

Second : The Mongrel2 server conf file.

You must declare handlers for process pyjamas jsonrpc requests.

File : server.conf

hand_auth = Handler(send_spec='tcp:', send_ident='54c6755b-9628-40a4-9a2d-cc82a816345e', recv_spec='tcp:', recv_ident='')

main = Server( uuid="2f62bd5-9e59-49cd-993c-3b6013c28f05" access_log="/logs/access.log" error_log="/logs/error.log" chroot="./" pid_file="/run/" default_host="localhost" name="main" port=80 hosts=[ Host(name="localhost", routes={ '/scripts': hand_auth '/': Dir(base='html/', index_file='index.html', default_ctype='text/plain')

}) ] ) settings = {"zeromq.threads": 1}

You can now load the server.conf file and start the server

Third : A bit pyjamas code

What you need to send json request to mongrel2 server.

from pyjamas.JSONService import JSONProxy

class Auth(Simple): def __init__(self): .... .... self.remote_py = AuthService() .... .... def onRemoteResponse(self, response, request_info): if response == "Connexion reussi.": .... .... else: ....

def onRemoteError(self, code, message, request_info): Window.alert("Erreur lors de l'appel de la fonction d'identifiaction")

class AuthService(JSONProxy): def __init__(self): JSONProxy.__init__(self, "/scripts", ["auth"])

.... .... .... ....

It's a firt try. i will put a full app as sample.

Something went wrong with that request. Please try again.