Apache thrift-cross-platform Communication

Source: Internet
Author: User

The C # client running on Windows 7 needs to communicate cross-platform and cross-language with the server built using nodejs on Ubuntu server. The open-source software thrift is used to solve this problem.

Thrift introduction:

Apache thrift Entry 1-Architecture & Introduction

Thrift Wiki

1. install Apache Thrift on Ubuntu

Install requirements: http://thrift.apache.org/docs/install/debian

$sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev$javac$sudo apt-get install <selected-package>$sudo apt-get install ant
Optional packages -- CSHARP
$sudo apt-get install mono-gmcs mono-devel libmono-system-web2.0-cil nunit nunit-console

Download Apache thrift: https://thrift.apache.org/download

$wget http://mirrors.sonic.net/apache/thrift/0.9.1/thrift-0.9.1.tar.gz

Or

$git clone https://git-wip-us.apache.org/repos/asf/thrift.git thrift$cd thrift

From source code compilation: https://thrift.apache.org/docs/BuildingFromSource http://www.geilthings.com/wiki/Thrift

Error & Solution: if some language Environments support problems, add the -- without = xxx option during configuration, and do not include unnecessary language support.

Https://issues.apache.org/jira/browse/THRIFT-2265

Http://wbj0110.iteye.com/blog/1988455

Error & Solution: thrift failed to install make ar:. libs/thrifttest_constants.o: no such file or directory

Http://stackoverflow.com/questions/18643642/libtool-error-building-thrift-0-9-1-on-ubuntu-13-04

Http://www.cnblogs.com/q191201771/p/3878682.html

650) This. width = 650; "src ="/e/u261/themes/default/images/spacer.gif "style =" Background: URL ("/e/u261/lang/ZH-CN/images/localimage.png") No-repeat center; Border: 1px solid # DDD; "alt =" spacer.gif "/> 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/48/74/wKioL1QIXkWR_LHWAABwxrI5EH8256.jpg "Title =" qq20140904204205.png "alt =" wkiol1qixkwr_lhwaabwxri5eh8256.jpg "/>

  1. CD./thrift-0.9.0/tutorial

  2. Thrift-r-gen CPP tutorial. Thrift //-R. The include file also generates Service Code-gen is the language used to generate service code.

  3. CD CPP

  4. Make

Run tutorialserver and tutorialclient

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/48/74/wKioL1QIXnPwM0KsAAGnxRxBwKQ719.jpg "Title =" qq201409042020.7.png "alt =" wkiol1qixnpwm0ksaagnxrxbwkq719.jpg "/>

Writing a. Thrift file,

Generate the source from a thrift file run

thrift --gen <language> <Thrift filename>

When using Apache thrift to communicate between node. js and C ++ processes, the following problems are encountered:

An error occurs when running the client and server:

Libthrift-0.9.1.so: cannot open shared object file: no such file or directory

How to set the environmental variable LD_LIBRARY_PATH in Linux

$vim ~/.bashrcexport LD_LIBRARY_PATH=/usr/local/lib$source ~/.bashrc

Ii. Install and implement thrift in Windows

1. Download thrift: thrift-0.9.1.exe thrift-0.9.1.tar.gz

650) This. width = 650; "src ="/e/u261/themes/default/images/spacer.gif "style =" Background: URL ("/e/u261/lang/ZH-CN/images/localimage.png") No-repeat center; Border: 1px solid # DDD; "alt =" spacer.gif "/>

Thrift-0.9.1.tar.gz

Thrift compiler for Windows (thrift-0.9.1.exe)

2. Download and install boost: (C ++ requires the standard library, C # skipped this step)

Http://www.boost.org/

Reference link:

Http://www.cnblogs.com/ComputerG/archive/2011/03/10/1979730.html

Http://download.csdn.net/detail/snrmp0711/5896485


Compile boost:

3. Compile the thrift script to generate a class file. CMD:

Thrift-0.9.1.exe-r -- Gen CSHARP tutorial. Thrift

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/48/72/wKiom1QIYOKQFiHOAAA5QKrPJXY269.jpg "style =" float: none; "Title =" qq20140904205324.png "alt =" wkiom1qiyokqfihoaaa5qkrpjxy269.jpg "/>

Generate the Gen-CSHARP folder with the following files:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/48/74/wKioL1QIYOaRqWChAABTX1XRpzk716.jpg "style =" float: none; "Title =" qq20140904205338.png "alt =" wkiol1qiyoarqwchaabtx1xrpzk716.jpg "/>

4. Supports thrift. dll of C #.

The thrift. dll file exists under thrift-0.9.1/lib/CSHARP /.

Or use the code in the Thrift-0.9.1/lib/CSHARP/src/folder to compile it through vs2012.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/48/74/wKioL1QIYSiCrjRJAAERCFnjapg005.jpg "Title =" qq20140904205452.png "alt =" wkiol1qiysic1_rjaaercfnjapg005.jpg "/>

Compile thrift solution to generate the thrift. dll file:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/48/72/wKiom1QIYUWCCKUwAAC0io-6sVk023.jpg "Title =" qq20140904205522.png "alt =" wKiom1QIYUWCCKUwAAC0io-6sVk023.jpg "/>

4. Add the file generated by thrift and the client server file, and add the project reference thrift. dll.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/48/74/wKioL1QIYXyCYyJSAAHAYs03rJo203.jpg "Title =" qq20140904205615.png "alt =" wkiol1qiyxycyyjsaahays03rjo203.jpg "/>

Run debug/server.exeand client.exe respectively. The result is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/48/72/wKiom1QIYY_S5zIaAADcVdfMhLQ185.jpg "Title =" qq20140904205640.png "alt =" wkiom1qiyy_s5ziaaadcvdfmhlq185.jpg "/>

Modify the IP address of the client code to the IP address of nodjs-server and generate a new scheme. Run node nodeserver.jsand client.exe respectively to call the code remotely. C # On Windows 7 communicates with nodejs on Ubuntu server 14.04 through thrift across platforms and languages.

Reference link:

Thrift: simple implementation of C # communication service programs

3. Write server programs and clients using the struct and Service generated by the same. Thrift file to implement cross-platform and cross-Language Communication


This article is from the "" blog, please be sure to keep this source http://xjhznick.blog.51cto.com/3608584/1548925

Apache thrift-cross-platform Communication

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.