Windows7上运行的C#客户端需要与在Ubuntu Server上使用nodejs构建的服务器进行跨平台跨语言的通信,选择使用开源软件thrift解决此问题。
Thrift相关介绍:
Apache Thrift入门1-架构&介绍
Thrift Wiki
一.Ubuntu上安装Apache Thrift
安装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
$sudo apt-get install antOptional 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 从源码编译:https://thrift.apache.org/docs/BuildingFromSource http://www.geilthings.com/wiki/Thrift
error&solution:有些语言环境支持出现问题,配置时加上 --without=XXX 选项,不包含不必要的语言支持。
https://issues.apache.org/jira/browse/THRIFT-2265
http://wbj0110.iteye.com/blog/1988455
error&solution:thrift thrift 安装 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
cd ./thrift-0.9 .0 /tutorial
thrift -r -gen cpp tutorial.thrift // -r对其中include的文件也生成服务代码 -gen是生成服务代码的语言
cd cpp
make
运行 TutorialServer 和 TutorialClient
Writing a .thrift file,
generate the source from a thrift file run
thrift --gen 利用apache Thrift 进行 node.js和 C++进程间通讯 时遇到如下问题:
在运行client和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 ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib
$source ~/.bashrc 二.windows下安装与实现thrift
1.下载thrift:thrift-0.9.1.exe thrift-0.9.1.tar.gz
thrift-0.9.1.tar.gz
Thrift compiler for Windows (thrift-0.9.1.exe)
2.下载安装boost:(c++需要该标准库,c#略过这一步)
http://www.boost.org/
参考链接:
http://www.cnblogs.com/ComputerG/archive/2011/03/10/1979730.html
http://download.csdn.net/detail/snrmp0711/5896485
编译boost:
3.编译thrift脚本,生成类文件,cmd:
thrift-0.9.1.exe -r --gen csharp tutorial.thrift
产生gen-csharp文件夹,有如下文件:
4.支持C#的Thrift.dll
在thrift-0.9.1/lib/csharp/ 下存在Thrift.dll文件
或者使用thrift-0.9.1/lib/csharp/src/文件夹下的代码通过VS2012编译
编译Thrift Solution,产生Thrift.dll文件:
4.添加thrift生成的文件以及Client Server文件,并且添加工程引用Thrift.dll
运行分别debug/下的Server.exe与Client.exe,结果如下:
修改Client代码的IP,为nodjs-server所在IP,重新生成方案,分别运行node nodeserver.js与Client.exe,成功进行远程调用。则Windows7上的C#与Ubuntu Server 14.04上的Nodejs通过thrift进行跨平台跨语言的通信。
参考链接:
Thrift初探:简单实现C#通讯服务程序
三.使用用同一个.thrift文件生成的struct和service编写服务器程序和客户端,则可以实现跨平台跨语言的通信
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com