RPC calls from different threads

73 views
Skip to first unread message

Marco Vimercati

unread,
Jul 14, 2015, 6:30:44 AM7/14/15
to qjsonrpc-d...@googlegroups.com
Hi all!

Anyone have experience in using qjsonrpc client from multiple threads?
I explain better: I have one local rpc server that expose i.e. one rpc call.
Another process is the rpc client, but this is spawned in different threads. Some of these need to have access
to the rpc, so I tried to use just one qjsonrpcclient object shared between this threads to access the server rpc.
Unfortunatelly I get some access violations (crash) when I call invokeRemoteMethod (blocking) in a thread different from main (the main thread initializes and connects to the service).

I tried to explain without code, because I have the suspect I'm missing something conceptual using the library.

regards
Marco

Matt Broadstone

unread,
Jul 14, 2015, 7:44:55 AM7/14/15
to Marco Vimercati, qjsonrpc-d...@googlegroups.com
Hi Marco,

qjsonrpc is designed such that you should use one client (tcp socket) per thread. This is because it depends on QTcpSocket which is not thread-safe. You could perhaps create a factory that returns a different client based on what thread QThread tells you you are currently in? 

Matt

 

-- 
 
You received this message because you are subscribed to the Google Groups "qjsonrpc-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qjsonrpc-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marco Vimercati

unread,
Jul 14, 2015, 8:18:10 AM7/14/15
to Matt Broadstone, qjsonrpc-d...@googlegroups.com
Dear Matt,
thanks for your reply.
Actually I'm using QLocalSocket, but I suppose it is managed in the same way.
So your suggestion is to use a different connection for each thread that need to talk with the rpc server?

best regards,
Marco

Matt Broadstone

unread,
Jul 14, 2015, 8:25:28 AM7/14/15
to Marco Vimercati, qjsonrpc-d...@googlegroups.com
On Tue, Jul 14, 2015 at 8:18 AM, Marco Vimercati <mvime...@gmail.com> wrote:
Dear Matt,
thanks for your reply.
Actually I'm using QLocalSocket, but I suppose it is managed in the same way.
So your suggestion is to use a different connection for each thread that need to talk with the rpc server?

best regards,
Marco

Yep. Unfortunately this is a limitation of Q*Socket's design that we can't quite get around, you can take a look at the tests for threaded socket use (in qjsonrpcserver tests iirc).

Matt

Marco Vimercati

unread,
Jul 14, 2015, 8:31:06 AM7/14/15
to Matt Broadstone, qjsonrpc-d...@googlegroups.com
Ok, thank you. I'll think something to hide all the client creation, maybe a factory as you suggested!
thanks
Marco
Reply all
Reply to author
Forward
0 new messages