青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

穩定盈利的期貨交易方法-量化趨勢交易

alantop -專業量化投資者

愛好:量化投資,逆向工程,滲透
隨筆 - 595, 文章 - 0, 評論 - 921, 引用 - 0
數據加載中……

由淺入深,舉例講解RPC(一)

 

關于RPC的文章很多,但是系統講解的很少。下面我將寫一個系列報道。用代碼和論述來把rpc來講講清楚。

這篇就是開始第一篇了。

 

由于工作比較忙。我們抽出一個星期的時間,有時間會寫一點。把這個系列寫完。所以,有可能每個系列都比較短些。

從最基本的講起,讓大家徹底明白RPC.

 

好了廢話不多說了。正是開始。

 

 

首先,你要用RPC,必須先搞清楚什么是IDL.

 

Rpc是什么?

http://m.shnenglu.com/alantop/archive/2007/07/09/27717.html

IDL是什么?

http://m.shnenglu.com/alantop/archive/2007/07/09/27725.html

 

下來,舉個例子。怎么樣把一個標準程序改成用IDL語言寫的程序。

 

這是一個標準程序。

// File Standalone.cpp

#include <iostream>

 

// Future server function.

void Output(const char* szOutput)

{

   std::cout << szOutput << std::endl;

}

 

int main()

{

   // Future client call.

   Output("Hello Lonely World!");

}

 

下來看我們怎么把它改為一個標準IDL語言的程序

IDL語言定義接口:

// File Example1.idl

[

   // A unique identifier that distinguishes this

   // interface from other interfaces.

   uuid(00000001-EAF3-4A7A-A0F2-BCE4C30DA77E),

 

   // This is version 1.0 of this interface.

   version(1.0),

 

   // This interface will use an implicit binding

   // handle named hExample1Binding.

   implicit_handle(handle_t hExample1Binding)

]

interface Example1 // The interface is named Example1

{

   // A function that takes a zero-terminated string.

   void Output(

      [in, string] const char* szOutput);

}

上面這個文件是我們用idl語言定義的,我們定義了一個接口Example1, 它帶有uuidversion. 這個接口里定義了一個函數Output.

 

UUID是什么?

http://m.shnenglu.com/alantop/archive/2007/07/09/27726.html

 

 

接口的implicit_handle屬性,我們后面再討論。

 

接下來干什么呢?

我們為了在程序中使用idl,必須通過通過編譯器(midl.exe)把它翻譯成客戶代理和服務器存根, 代理和存根將在后面被我們的編譯器(windows平臺下的cl.exe)所使用。

 

 

改好的服務器端程序:

// File Example1Server.cpp

#include <iostream>

#include "Example1.h"

 

// Server function.

void Output(const char* szOutput)

{

   std::cout << szOutput << std::endl;

}

 

int main()

{

   RPC_STATUS status;

 

   // Uses the protocol combined with the endpoint for receiving

   // remote procedure calls.

   status = RpcServerUseProtseqEp(

      reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP

                                                        // protocol.

      RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // Backlog queue length for TCP/IP.

      reinterpret_cast<unsigned char*>("4747"), // TCP/IP port to use.

      NULL); // No security.

 

   if (status)

      exit(status);

 

   // Registers the Example1 interface.

   status = RpcServerRegisterIf(

      Example1_v1_0_s_ifspec, // Interface to register.

      NULL, // Use the MIDL generated entry-point vector.

      NULL); // Use the MIDL generated entry-point vector.

 

   if (status)

      exit(status);

 

   // Start to listen for remote procedure

   // calls for all registered interfaces.

   // This call will not return until

   // RpcMgmtStopServerListening is called.

   status = RpcServerListen(

     1, // Recommended minimum number of threads.

     RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended

                            //maximum number of threads.

     FALSE); // Start listening now.

 

   if (status)

      exit(status);

}

 

// Memory allocation function for RPC.

// The runtime uses these two functions for allocating/deallocating

// enough memory to pass the string to the server.

void* __RPC_USER midl_user_allocate(size_t size)

{

    return malloc(size);

}

 

// Memory deallocation function for RPC.

void __RPC_USER midl_user_free(void* p)

{

    free(p);

}

 

這是初始化,和注冊接口的代碼。

 

現在看看怎么寫客戶端

// File Example1Client.cpp

#include <iostream>

#include "Example1.h"

 

int main()

{

   RPC_STATUS status;

   unsigned char* szStringBinding = NULL;

 

   // Creates a string binding handle.

   // This function is nothing more than a printf.

   // Connection is not done here.

   status = RpcStringBindingCompose(

      NULL, // UUID to bind to.

      reinterpret_cast<unsigned char*>("ncacn_ip_tcp"), // Use TCP/IP

                                                        // protocol.

      reinterpret_cast<unsigned char*>("localhost"), // TCP/IP network

                                                     // address to use.

      reinterpret_cast<unsigned char*>("4747"), // TCP/IP port to use.

      NULL, // Protocol dependent network options to use.

      &szStringBinding); // String binding output.

 

   if (status)

      exit(status);

 

   // Validates the format of the string binding handle and converts

   // it to a binding handle.

   // Connection is not done here either.

   status = RpcBindingFromStringBinding(

      szStringBinding, // The string binding to validate.

      &hExample1Binding); // Put the result in the implicit binding

                          // handle defined in the IDL file.

 

   if (status)

      exit(status);

 

   RpcTryExcept

   {

      // Calls the RPC function. The hExample1Binding binding handle

      // is used implicitly.

      // Connection is done here.

      Output("Hello RPC World!");

   }

   RpcExcept(1)

   {

      std::cerr << "Runtime reported exception " << RpcExceptionCode()

                << std::endl;

   }

   RpcEndExcept

 

   // Free the memory allocated by a string.

   status = RpcStringFree(

      &szStringBinding); // String to be freed.

 

   if (status)

      exit(status);

 

   // Releases binding handle resources and disconnects from the server.

   status = RpcBindingFree(

      &hExample1Binding); // Frees the implicit binding handle defined in

                          // the IDL file.

 

   if (status)

      exit(status);

}

 

// Memory allocation function for RPC.

// The runtime uses these two functions for allocating/deallocating

// enough memory to pass the string to the server.

void* __RPC_USER midl_user_allocate(size_t size)

{

    return malloc(size);

}

 

// Memory deallocation function for RPC.

void __RPC_USER midl_user_free(void* p)

{

    free(p);

}

 

posted on 2007-07-09 12:41 AlanTop 閱讀(4659) 評論(3)  編輯 收藏 引用 所屬分類: COMC++

評論

# re: 由淺入深,舉例講解RPC(一)[未登錄]  回復  更多評論   

好文章!
2007-07-09 17:13 | 111

# re: 由淺入深,舉例講解RPC(一)  回復  更多評論   

好,頂!!
2007-07-13 17:07 | 黃大仙

# re: 由淺入深,舉例講解RPC(一)  回復  更多評論   

后面還有嗎?謝謝
2009-04-05 23:54 | 螢火蟲
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲在线观看免费视频| 亚洲精品乱码久久久久| 久久一区二区三区av| 欧美在线啊v| 午夜免费久久久久| 久久精品久久99精品久久| 久久婷婷丁香| 欧美啪啪一区| 国产日韩精品电影| 伊人伊人伊人久久| 日韩午夜精品视频| 欧美一区二区三区免费观看视频| 久久国产免费看| 亚洲国产精品传媒在线观看| 亚洲国产日韩欧美在线图片 | 亚洲精品日韩激情在线电影| 亚洲看片一区| 性欧美video另类hd性玩具| 免费观看在线综合色| 夜夜精品视频一区二区| 久久久免费精品| 欧美亚洲不卡| 亚洲精品日韩在线观看| 欧美制服丝袜| 91久久国产自产拍夜夜嗨| 一区二区三区日韩欧美精品| 久久精品一区二区国产| 欧美三区在线视频| 亚洲国产裸拍裸体视频在线观看乱了中文 | 欧美性jizz18性欧美| 伊人久久综合| 欧美影院在线播放| 国产精品第十页| 欧美在线免费视屏| 欧美精品aa| 激情综合色综合久久| 在线中文字幕不卡| 欧美成人第一页| 性欧美暴力猛交69hd| 欧美人与禽性xxxxx杂性| 狠狠狠色丁香婷婷综合激情| 亚洲专区欧美专区| 日韩午夜剧场| 欧美精品色综合| 亚洲国产精品嫩草影院| 久久女同互慰一区二区三区| 亚洲一区精品电影| 欧美性猛交xxxx乱大交蜜桃| 一本综合精品| 亚洲精品欧美日韩专区| 久久一区二区三区四区| 激情丁香综合| 久久米奇亚洲| 久久不射网站| 在线成人免费观看| 美女视频一区免费观看| 久久狠狠久久综合桃花| 国内精品福利| 牛人盗摄一区二区三区视频| 噜噜噜噜噜久久久久久91| 亚洲电影成人| 亚洲国产经典视频| 欧美极品欧美精品欧美视频| avtt综合网| 一区二区日韩伦理片| 国产精品欧美日韩一区| 午夜亚洲视频| 欧美亚洲日本一区| 在线观看欧美激情| 亚洲国产精品va| 欧美视频一区二区三区在线观看 | 欧美一区二区日韩一区二区| 国产欧美一区视频| 久久伊人免费视频| 欧美激情成人在线| 亚洲综合色噜噜狠狠| 亚洲免费影院| 在线成人av网站| 日韩一级黄色大片| 国产精品一区二区三区久久| 久久久久一区二区三区| 理论片一区二区在线| 一区二区三欧美| 欧美亚洲在线播放| 亚洲精选视频在线| 亚洲欧美日韩在线高清直播| 在线播放亚洲| 国产精品99久久久久久有的能看| 国产老肥熟一区二区三区| 免费日韩精品中文字幕视频在线| 久久亚洲综合色| 欧美激情一区| 欧美三区美女| 美女成人午夜| 欧美日韩国产综合网| 久久高清免费观看| 欧美成人首页| 久久精品国产77777蜜臀| 久久综合国产精品| 亚洲直播在线一区| 欧美成人中文| 久久免费国产| 国产精品普通话对白| 亚洲大黄网站| 国产中文一区二区| 宅男66日本亚洲欧美视频| 在线欧美影院| 午夜免费久久久久| 亚洲一级特黄| 欧美激情亚洲一区| 免费黄网站欧美| 国产欧美综合一区二区三区| 亚洲狼人综合| 亚洲精品中文字| 久久9热精品视频| 性欧美videos另类喷潮| 欧美理论电影在线观看| 免费在线观看成人av| 国产精品午夜在线| 一本色道88久久加勒比精品| 亚洲国产一二三| 久久久天天操| 久久综合狠狠| 韩国女主播一区二区三区| 亚洲欧美不卡| 亚洲欧美视频一区| 欧美视频在线一区二区三区| 亚洲国产精品久久久久婷婷老年| 伊人久久成人| 久久天天躁狠狠躁夜夜爽蜜月| 久久爱www| 国产日产精品一区二区三区四区的观看方式 | 亚洲特黄一级片| 欧美激情精品久久久久久蜜臀 | 欧美一区二区三区免费视| 欧美日韩你懂的| 亚洲作爱视频| 亚洲欧美激情一区| 国产精品日韩一区| 香蕉av777xxx色综合一区| 性色av一区二区怡红| 国产精品毛片| 欧美亚洲一区二区在线观看| 久久全球大尺度高清视频| 娇妻被交换粗又大又硬视频欧美| 久久av资源网站| 欧美+亚洲+精品+三区| 亚洲二区三区四区| 久久日韩粉嫩一区二区三区| 国产精品综合| 欧美激情成人在线| 亚洲精品乱码久久久久久| 欧美日本簧片| 亚洲欧美日韩在线综合| 久久久久看片| 亚洲国产欧美不卡在线观看| 欧美成人第一页| 一本色道久久综合狠狠躁篇的优点 | 久久久之久亚州精品露出| 狠狠色综合一区二区| 久久另类ts人妖一区二区| 亚洲国产精品成人综合色在线婷婷| 日韩午夜免费| 国产乱肥老妇国产一区二| 久久久久九九九九| 亚洲人成网站影音先锋播放| 亚洲欧美资源在线| 在线观看欧美一区| 欧美日韩免费观看一区二区三区 | 性久久久久久久久| 亚洲成人在线免费| 欧美一级在线播放| 亚洲成人在线视频播放| 欧美日韩午夜激情| 久久超碰97人人做人人爱| 亚洲国产日韩在线| 性欧美在线看片a免费观看| 最新日韩中文字幕| 国产亚洲激情| 国产精品成人免费精品自在线观看| 久久久久亚洲综合| 欧美一区二区三区四区夜夜大片 | 性欧美暴力猛交69hd| 亚洲精品久久久久久久久久久久久| 欧美一区2区三区4区公司二百| 亚洲精品视频一区| 狠狠色狠狠色综合| 国产精品日韩一区| 欧美日韩日日骚| 麻豆精品视频在线观看视频| 国产精品99久久久久久白浆小说| 欧美韩日一区二区| 久久亚洲色图| 久久精品免费电影| 欧美一级久久| 欧美一激情一区二区三区| 一区二区欧美国产| 亚洲精品一区二区三区樱花| 黄色亚洲网站| 一区精品在线|