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

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

alantop -專業量化投資者

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

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

 

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

這篇就是開始第一篇了。

 

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

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

 

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

 

 

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

 

Rpc是什么?

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

IDL是什么?

http://www.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://www.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 閱讀(4672) 評論(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>
            亚洲激情不卡| 亚洲福利小视频| 国产日韩欧美精品| 国产精品xnxxcom| 亚洲欧美中文在线视频| 亚洲每日在线| 亚洲一区在线观看视频 | 日韩视频免费在线| 亚洲女人天堂av| 免费亚洲电影在线| 亚洲一区二区三区精品视频 | 欧美成人午夜免费视在线看片| 亚洲国产成人av| 欧美一进一出视频| 欧美男人的天堂| 久久青草欧美一区二区三区| 久久动漫亚洲| 亚洲国产精品一区| 欧美v亚洲v综合ⅴ国产v| 久久福利资源站| 久久深夜福利免费观看| 欧美成人黄色小视频| 亚洲高清视频在线| 91久久精品网| 国产精品第三页| 国产精品一区二区三区观看 | 久久成人在线| 午夜精品视频| 亚洲精品国偷自产在线99热| 免费成人激情视频| 久久久综合免费视频| 久久久女女女女999久久| 翔田千里一区二区| 午夜亚洲影视| 亚洲成色999久久网站| 亚洲品质自拍| 亚洲欧美日韩国产精品| 欧美jjzz| 亚洲欧美高清| 欧美国产免费| 一区二区三区在线不卡| 亚洲视频导航| 欧美 日韩 国产在线| 一区二区不卡在线视频 午夜欧美不卡在 | 最新热久久免费视频| 欧美在线免费观看视频| 亚洲精品激情| 亚洲高清在线观看| 一区二区欧美视频| 国产自产高清不卡| 国产日韩欧美自拍| 韩国久久久久| 亚洲一区二区四区| 欧美日韩一区二区三区免费| 久久久久久久尹人综合网亚洲 | 亚洲视频播放| 亚洲美女黄色片| 国产午夜精品理论片a级探花| 国产精品亚洲综合久久| 久久伊伊香蕉| 亚洲福利国产| 亚洲欧洲一区二区三区久久| 欧美福利视频在线观看| 中文精品视频| 日韩写真视频在线观看| 老司机免费视频久久| 久久精品午夜| 国产精品亚洲人在线观看| 亚洲欧洲偷拍精品| 欧美一区国产二区| 欧美大片一区二区| 亚洲第一主播视频| 国产婷婷色综合av蜜臀av| 亚洲人体一区| 一色屋精品视频免费看| 国产精品永久入口久久久| 亚洲国产激情| 久久久亚洲国产美女国产盗摄| 亚洲最新视频在线| 欧美成人国产| 在线观看一区二区精品视频| 欧美久久一区| 日韩视频在线免费| 国产精品夜夜嗨| 99精品欧美一区二区三区| 性欧美暴力猛交69hd| 欧美激情小视频| 毛片一区二区| 亚洲精品人人| 亚洲精品国产精品国自产观看浪潮 | 国产欧美日韩亚洲一区二区三区| 在线亚洲一区二区| 亚洲精品久久久久中文字幕欢迎你| 玖玖综合伊人| 亚洲理伦电影| 99精品国产在热久久| 欧美吻胸吃奶大尺度电影| 欧美成人乱码一区二区三区| 国产欧美一区二区三区国产幕精品| 亚洲午夜精品久久久久久浪潮| 日韩亚洲精品在线| 国产精品久久久久999| 亚洲欧美经典视频| 亚洲丝袜av一区| 国产一区二区三区av电影| 久久久久久9999| 免费看的黄色欧美网站| 9久re热视频在线精品| 一本大道久久a久久精二百| 国产日产精品一区二区三区四区的观看方式 | 欧美日韩精品| 久久久国产视频91| 免费观看一级特黄欧美大片| 中文精品视频| 欧美一区二区日韩| 最新国产精品拍自在线播放| 野花国产精品入口| 在线观看91精品国产麻豆| 亚洲综合精品| 久久av老司机精品网站导航| 亚洲精品视频在线| 亚洲午夜激情免费视频| 黄网动漫久久久| 日韩亚洲精品电影| 国产资源精品在线观看| 日韩一级大片在线| 激情综合电影网| 亚洲日本成人在线观看| 国产一区二区三区精品久久久| 欧美本精品男人aⅴ天堂| 老司机67194精品线观看| 亚洲欧美激情视频| 久久激情网站| 亚洲欧美视频一区| 欧美激情一区二区三区在线视频观看 | 国产一区二区三区久久久| 亚洲精品日产精品乱码不卡| 国产一区二区毛片| 一本久道久久久| 亚洲美女在线观看| 久久久久久久一区二区| 欧美一级午夜免费电影| 欧美人在线观看| 久久久久国色av免费看影院| 欧美与黑人午夜性猛交久久久| 欧美在线视频一区二区三区| 亚洲欧美激情一区| 欧美乱大交xxxxx| 欧美激情在线观看| 精品成人一区二区三区| 欧美一级片在线播放| 亚洲国产欧美在线人成| 日韩亚洲一区二区| 日韩一级不卡| 欧美精品在线一区二区| 亚洲精选视频免费看| 亚洲欧美日韩在线播放| 亚洲精品欧美在线| 久久久99久久精品女同性 | 国产亚洲精品福利| 亚洲午夜精品一区二区三区他趣| 日韩一级网站| 欧美成人精品三级在线观看| 久久人体大胆视频| 国产乱码精品一区二区三区av | 国产欧美日韩伦理| 亚洲人成绝费网站色www| 亚洲国产精品久久久久秋霞不卡 | 久久国产婷婷国产香蕉| 国产精品天美传媒入口| 亚洲在线黄色| 性欧美长视频| 欧美日韩午夜精品| 制服丝袜亚洲播放| 久久综合色综合88| 亚洲国产精品久久久久秋霞蜜臀| 男同欧美伦乱| 99re66热这里只有精品4| 亚洲深爱激情| 国产日韩欧美自拍| 亚洲国产精品第一区二区三区| 亚洲精品网址在线观看| 欧美日韩午夜| 亚洲免费av观看| 欧美一区日本一区韩国一区| 欧美精品www在线观看| 中日韩高清电影网| 久久夜色撩人精品| 一本大道久久a久久综合婷婷| 欧美激情精品久久久久| 亚洲永久在线| 亚洲电影av| 99精品免费| 国产日韩欧美一区| 欧美大片免费观看在线观看网站推荐| 日韩一本二本av| 国产在线欧美| 欧美色大人视频| 正在播放亚洲一区| 欧美va亚洲va国产综合|