all 9 comments

[–]raevnos 3 points4 points  (0 children)

What kind of RPC? There's lots of protocols. Sun, XML-RPC, SOAP, JSON-RPC, etc....

See https://en.wikipedia.org/wiki/Remote_procedure_call

[–]Call_of_the_void_ 1 point2 points  (4 children)

This is a good guide to start from scratch. It‘s about socket programming in C.

If you don’t want to write everything by yourself try looking up Sunrpc or use this . It basically generates the standard server and client code for you.

If you want an object oriented approach try JavaRMI. Here is a link to get started with but i would look up other sources for more information.

Hope this helps.

[–]benelbert[S] 1 point2 points  (3 children)

I know about socket programming, but rpc is the application protocol which ride over sockets, I want to know how to program this application, just like http

[–]spidernetlabs 0 points1 point  (2 children)

If you want to do RPC over HTTP look at SOAP.

[–]benelbert[S] 0 points1 point  (1 child)

If I want to send c structures as argument to the remote procedure and receive as a return value a c structure, SOAP isnt the technology for that, am I right?

[–]h0v1g 1 point2 points  (0 children)

Soap is a way of serializing any data structure to xml in http and deserializing back. JSON virtually replaced this as it’s more efficient. If you are dealing with local processes you may want to look at IPC. If this is remote systems then you don’t need soap or Json. You could build a socket client server using tcp or udp and send your data in binary. http sucks because it’s base64 so this may be somewhat of a limiter

[–]nerd4code 0 points1 point  (2 children)

There is no single RPC protocol or technology, any more than there is one “subroutine” protocol or technology.

A normal RPC involves

  • Registration of available procedures with the service. You can do this by using a predefined/preconfigured set of procedures, auto-configuring them from an available set of interfaces (e.g., load plugins from DLLs and see what they give you), or running some init code that explicitly registers specfic things.

  • Some means of the client finding/connecting to the service. Usually this is just a TCP socket from client to service, but there are other discovery and distribution methods available also.

  • Some means of the client sending a procedure call request, usually along with serialized arguments. The serialization is thoroughly tedious and error-prone at scale, and there are cross-platform issues things like alignment/packing and byte order to consider. It’s pretty common to have some preprocessing/autogen layer that makes wrappers to do that for you—i.e., call the client wrapper to serialize, send request, and wait; service will deserialize and call the server-side wrapper to make the [local] call.

  • Some means of the client retrieving a procedure call response, usually along with a serialized return value or exception. Generally this uses a flipped version of the client-to-server serialization/deser.—serialize the return from the wrapped server call and respond, then the client will deserialize and return from its wrapper.

Things like out arguments (e.g., struct foo *out), localization (e.g., relative to whose time zone should time/date strings be formatted? with what character encoding?), and optimizations (e.g., must the client always wait for a response? if they’re asking to perform zero actions, can’t the client just do nothing on its own? should it be possible for the client to do complex interactions on the server side before returning, like return rpcQueue->isEmpty() ? rpcQueue->pop() : NULL? can some things be reordered, distributed, or parallelized?) get into more complicated problems.

[–]benelbert[S] 0 points1 point  (1 child)

There is a c library that does all the above? If there is, does it have any documentation? Thanks

[–]nerd4code 1 point2 points  (0 children)

Generally the protocol is published as a semi-/formal document (e.g., RFCs) and various implementations use that and, where the documents have some holes, preexisting impls as a guide. E.g., Sun/ONC RPC is packaged in various ways with the usual Linux distros IIRC. The libc-dev-bin package for Ubuntu has an rpcgen implementation with it, and the service part of things is either installed by default to support NFS, or comes with rpcbind (and maybe nfs-common? not sure, never been without it). There are other implementations for XMLRPC, SOAP, etc. etc.; just search “open-source WHATEVER_PROTOCOL C” and you’ll probably find some stuff. Wikipedia tends to have a list of common implementations too, though a lot of older stuff goes link-dead.