Monday, October 28, 2013

Beginning RPC

Inline image 2

Introduction

This article gives you an insight on writing a simple Client- Server communication using RPC.  

RPC is a powerful, robust, efficient, and secure interprocess communication (IPC) mechanism that enables data exchange and invocation of functionality residing in a different process. That different process can be on the same machine, on the local area network, or across the Internet.  It can use any of the following protocols: TCP\IP , ALPC ports, Named Pipes. In this article the protocol used is "ncalrpc" and communication is between two processes within the same machine .  

General Build Process

The process for creating a client/server application using Microsoft RPC is:
Develop the interface.
Develop the server that implements the interface.
Develop the client that uses the interface.

Develop the Interface (MIDL ,IDL,ACF)

Microsoft has MIDL compiler to create the interfaces to communicate with client and server, using those interfaces we can easily write Client and Server modules focusing on the functionality rather than communication between them. An RPC interface describes the remote functions that the server program implements. The interface ensures that the client and server communicate using the same rules when the client invokes a remote procedure that the server offers.

Writing the IDL file :

The IDL file consists of one or more interface definitions, each of which has a header and a body. The header contains unique interface information, such as the UUID, version. This information is enclosed in square brackets and is followed by the keyword interface and the interface name. The body contains C-style data type definitions and function prototypes. The interface exposes two function ADD and MUL .

cpp_quote("#define PROTOCOL L\"ncalrpc\"")
cpp_quote("#define ENDPOINT L\"calc\"")
[
uuid (B0FD7284-2A00-4b46-9026-A3814507AAA7),
version (1.0)
]
interface RpcCalc
{
    unsigned long __stdcall Add( [in] long param1, [in] long param2);
    unsigned long __stdcall Mul( [in] long param1, [in] long param2);
}    
save it as RpcCalc.idl  

ACF file :  

ACF file—specifying the type of binding handle that represents the connection between client and server. The [explicit_handle] ACF attribute specifies that each procedure has, as its first parameter, a primitive handle, such as a handle_t type.

[
 strict_context_handle,
 explicit_handle
]
interface IRpccalc
{
}  

save it as RpcCalc.acf

Read more: Codeproject
QR: Inline image 1