json-rpc c libraries

707 views
Skip to first unread message

maverick

unread,
Jun 7, 2009, 2:37:16 PM6/7/09
to JSON-RPC
Hi,
I would like to use JSON-RPC for a client server communication. We
are planing to implement server in java and client in C. I could find
some libraries for this in Java. But in C, only this one
http://www.big-llc.com/software.jsp. Is there any other C libraries
available ?

regards,
maverick

gdaddis

unread,
Jun 7, 2009, 6:01:00 PM6/7/09
to JSON-RPC
Hello,

I've been working on a C JSON-RPC Library. It is designed for embedded
environments / Linux. The goal is to provide JSON-RPC encoding/
decoding with optional encryption, full-duplex peer-to-peer
communication (i.e. ability to send & receive requests and responses),
a multi-threaded TCP/IP socket transport layer, ability to support
multiple connections, ability to simultaneously establish outgoing
connections while listening for incoming connections, automatic
connection re-establishment for dropped connections, support for
receiving requests and dispatching responses with a server RPC method
registry, and a JSON-RPC compiler that auto-generates the C code for
all the important implementations.

The application that this is designed for is an embedded device
running on a linux router/gateway that would sit behind a firewall in
a home residence that communicates with a central server as well as
several GUI clients on the local network.

The JSON-RPC compiler likely requires additional explanation: You will
notice that in many implementations, a great deal of code is required
to marshal and de-marshal parameters on both client side and the
server side. The JSON-RPC compiler reads an "IDL" file which is a
description of the JSON-RPC services a server offers and creates the
following files:

1. clientStubs.c/h (containing code a client would call to invoke the
RPC)
2. serverSkeletons.c/h (containing code run by the server to de-
marshall params, call the server implementation of the RPC, and
marshall the return value)
3. serverImpls.c/h (containing stub code that the application writer
would complete to implement an RPC function).

The "IDL file" is encoded in JSON itself and could also be used as an
extension to a JSON-RPC service to self-describe the methods it offers
like a *.wdsl in web services. After the dust settles on the JSON-RPC
2.0 discussion, I was intending to submit the spec for this as an
extension (previous discussion threads pointed to some interest in
having a service self-description language).

If you are familiar with CORBA or similar, this is essentially an ORB
written for JSON-RPC - encoding, transport, error-recovery, service
registration, IDL compilation. It depends on no other libraries other
than std C libraries and pthreads. It does not require a browser as it
is socket based.

The functionality was designed so that as a user, you can design an
IDL, compile it to standard C structures and function calls, and call
these as if they were local functions. The setup is minimal -
typically, a client calls an RPC_OpenEnv() call with cfg info and
hRPCConn = RPC_OpenConn(sock_addr_in) to open a connection to start
things off. After that, client calls are made by calling the client
stub that was already created for you by the JSON-RPC compiler. An
example call would be:

char *szRetValue;
struct TComplexParam complexParam = {...};
double numParam = ...;
char *szStrParam = "...";
if (exampleRPC(hRPCConn, numParam, szStrParam, &complexParam,
&szRetValue) != RPCSuccess)
{
// Handle error
}

Notice the only thing that alludes to the call being an RPC call is
the inclusion of the first param hRPCConn. No other RPC-specific
structures required.

Yikes - sorry for the long post.

In any case, I have full functionality written and "unit-tested". It
is going into a commercial product later this year, but will likely be
available under some open source license (BSD, GPL, others? I have to
figure out which is best). If you are interested in looking at it and
possibly helping out extended the library, let me know. Lots of
possible extensions: HTTP transport, additional encryption methods,
implementations in other languages (such as Java!), better packaging
for Linux deployment (I'm normally a Microsoft guy - gasp! - so Linux
packages/makefiles are new to me).

I will be duplicating most of this functionality in an OOP format for
ActionScript (Adobe's Flex Builder 3 environment) for use in RIA Adobe
AIR/Flex applications and for Microsoft C# .NET 3.5 for our "central
server" implementation.

Best,
George

P.S. I would like to credit MJSON (http://mjson.sourceforge.net/
index.html) for the low-level JSON encoding/decoding.

On Jun 7, 2:37 pm, maverick <maverick...@gmail.com> wrote:
> Hi,
>  I would like to use JSON-RPC for a client server communication. We
> are planing to implement server in java and client in C. I could find
> some libraries for this in Java. But in C, only this onehttp://www.big-llc.com/software.jsp. Is there any other C libraries
> available ?
>
> regards,
> maverick

maverick

unread,
Jun 8, 2009, 1:05:08 AM6/8/09
to JSON-RPC
Hi,
Thanks a lot for your reply. Its a great news. I was looking for
similar one.
If you could share the code or host it under a license, I would take a
look onto it.
I wanted HTTP/HTTPS transport, so I could help in implementing that.
I studied some parts in thrift, protocol buffer, so your solution
seems similar and i like it.
I want this library for a proprietary product :(. Please let me know
if i could be
a help for you. It wil be more great if we host the library, so that
everyone gets
benefit from it.

regards,
sanal.

gdaddis

unread,
Jun 8, 2009, 9:54:22 PM6/8/09
to JSON-RPC
Hello,

I'm assuming that when you say 'host the library' you mean put it up
on a site like SourceForge? (I'm new to this open source thing). I'll
get something set up this week.

Yes - adding HTTP/HTTPS as a transport would be a very useful addition
that I could use some help with.

I'll post back here when the library and an example application is up
on SourceForge.

Best,
George

maverick

unread,
Jun 9, 2009, 9:10:18 AM6/9/09
to JSON-RPC
Hello,
Thats cool. Yeah I meant if you apply a license and host it under
sourceforge
or googlecode, it would be good.

Have you completed the compiler part ? How much time will it take for
you to
post back ?

I would be kind enough if you could send it to my email, so that i
could
take a look into it too.. let me know ur opinion.

best regards,
maverick

gdaddis

unread,
Jun 10, 2009, 9:52:14 PM6/10/09
to JSON-RPC
Hello,

I've actually completed the entire project as described - the
transport, encoding, compiler, etc. It has a few pieces from JSON-RPC
not in such as the batch mode. Personally, I was hoping that someone
would shoot that part down soon - looks like lots of additional
complexity for minimal gain. But if it stays in, I'll get it into the
library as well.

The code has been unit tested, but has not yet been really worked over
yet. So I would call it "early alpha" - full functionality but not
mature. No known bugs (I'm fixing them as I find them), but needs lots
more usage/testing.

If I can't get it hosted tomorrow, I'll email a copy with my unit test
framework. The code is heavily commented and the unit test shows how
to use most of the functions, but there is no documentation manual
yet.

Best,
George
Reply all
Reply to author
Forward
0 new messages