Well, we have uWSGI instances that are using the uWSGI rpc subsystem to
make calls to our uWSGI rpc services, which is all working fine, but we
also want to have a few non uWSGI apps to be able to make rpc calls to the
uWSGI rpc services as well.

With the help of Stack Overflow<http://stackoverflow.com/questions/15981891>,
we were able to come up with a very rough test, but it's raw and scary even
if we package it and test it heavily.


import socket
from struct import pack, unpack

c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c.connect(('127.0.0.1', 3737))

#test call
fun = 'testing_call'
arg = 'the test param'

#header
ulen = len(fun)
arglen = len(arg)
buflen = (2 + ulen) + (2 + arglen)
buf = pack('<B', 173)
buf += pack('<H', buflen)
buf += pack('<B', 0)
c.send(buf)

#body
buf = pack('<B', ulen & 0xff)
buf += pack('<B', (ulen>>8) & 0xff)
buf += fun
buf += pack('<B', arglen & 0xff)
buf += pack('<B', (arglen>>8) & 0xff)
buf += arg
sent = c.send(buf)

#print response
print "sent", sent
resp = c.recv(4)
fsize = unpack('<H', resp[1:3])[0]
resp = c.recv(fsize)
print "resp", resp

c.close()



Thanks for your advice.


On Fri, Apr 12, 2013 at 10:19 PM, Roberto De Ioris <[email protected]> wrote:

>
> > Hello
> >
> > I'm trying to use an external rpc client (RPyC) to make rpc calls to a
> > uwsgi app I have running with, but I'm not having much luck getting it to
> > work.  I'm trying to do this with clients that don't have the ability to
> > import uwsgi or uwsgidecorators as they aren't running as under uwsgi.
> >
> > My server code looks as:
> >
> > import simplejson as json
> > from uwsgidecorators import rpc
> > import uwsgi
> >
> > @rpc('testing_call')
> >
> > def
> > testing_call(test_param):
> >     print 'got a call'
> >     return json.dumps({'test_param':test_param})
> >
> > #run with
> > #/opt/bin/uwsgi --import uwsgi_rpc_test -s :3737 -M  --enable-threads -p
> 1
> >
> > with my simple RPyC client code as
> >
> > import rpyc
> > c = rpyc.connect('127.0.0.1', port=3737)
> > c.sync_request('testing_call')
> >
> > But all I get back is Connection reset by peer from RPyC and the uwsgi
> app
> > gives:
> > Empty python request. skip.
> > [pid: 9468|app: -1|req: -1/3]  () {0 vars in 0 bytes} [Fri Apr 12
> 17:51:27
> > 2013]   => generated 0 bytes in 0 msecs ( 0) 0 headers in 0 bytes (0
> > switches on core 0)
> >
> >
> >
> >
>
> the uWSGI rpc subsystem is meant to be used only by uWSGI instances. Each
> RPC tecnhology works on top of its protocol, so if you want to expose
> uWSGI rpc function via another protocol you have to build a wrapper.
>
> Albeit uWSGI RPC is very fast, once you wrap it you loose lots of its
> advantages, so to build a public api it is better to use a 'public' rpc
> subsystem (read: use rpyc for the server part too)
>
>
> --
> Roberto De Ioris
> http://unbit.it
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to