Test the RPC c/s program-01

Source: Internet
Author: User

Environments: VC ++ 6.0

1. Use the uuidgen.exe/I/rpc. IDL command to generate an rpc. IDL file (the file name must be of the. IDL type ).

The format of the generated file is as follows:

[
UUID (abb12775-f053-4c62-95c2-4d9bc7fdbfef ),
Version (1.0)
]
Interface interfacename
{

}

2. Write the function you want to call on the server in the brackets of interface interfacename.

For example: (the following code comes from: http://www.codeproject.com/KB/IP/rpcintro2.aspx)

// File contextexample. IDL
[
// A unique identifier that distinguishes this interface from other interfaces.
UUID (00000003-eaf3-4a7a-a0f2-bce4c30da77e ),

// This is version 1.0 of this interface.
Version (1.0)
]
Interface contextexample // The interface is named contextexample
{
// To fully use context handles we need to do a typedef.
Typedef [context_handle] void * context_handle;

// Open a context on the server.
Context_handle open (
// Explicit server binding handle.
[In] handle_t hbinding,
// String to be output on the server.
[IN, string] const char * szstring );

// Output the context string on the server.
Void output (
// Context handle. The binding handle is implicitly
// Used through the explicit context handle.
[In] context_handle hcontext );

// Closes a context on the server.
Void close (
// Context handle. The binding handle is implicitly
// Used through the explicit context handle.
[In, out] context_handle * phcontext );
}

3. Execute midl. EXE contextexample. IDL on the generated. IDL file (the file name depends on your own file name)

In this case, three contextexample. h contextexample_s.c contextexample_c.c files are generated.

4. generate two projects, one being the server and the other being the client.

Import contextexample. IDL contextexample. h contextexample_s.c to the server project;

Import contextexample. IDL contextexample. h contextexample_c.c to the client project.

5. Compile the implementation code of the called function on the server side, and write the call code on the client side to test the RPC-based c/s program.

However, this method is more suitable for some practical applications than directly using socket or csocket. It is still to be tested!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.