用javapython socket server编写的server端,用python编写的client,数据怎么传输,最好给个具体的例子,谢谢!

简单通过java的socket&serversocket以及多线程技术实现多客户端的数据的传输,并将数据写入hbase中 - ljy2013 - 博客园
业务需求说明,由于公司数据中心处于刚开始部署的阶段,这需要涉及其它部分将数据全部汇总到数据中心,这实现的方式是同上传json文件,通过采用socket&serversocket实现传输。
其中,服务端采用多线程的方式,实现多用户传输的目的。并且实现可以将数据写入到hbase中。
具体步骤如下:
1、首先编写客户端的代码:
package com.yiban.datacenter.ToHbaseFromJ
import java.io.BufferedR
import java.io.BufferedW
import java.io.FileR
import java.io.IOE
import java.io.InputStreamR
import java.io.OutputStreamW
import java.net.S
import java.net.UnknownHostE
public class hbaseclient {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建客户端的socket
Socket s = new Socket("192.168.27.47", 22222);
// 首先确认连接上了我的服务器,通过接受服务器发送的确认信息
BufferedWriter firstclientwrite = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
firstclientwrite.write("我准备向你发送数据了,你准备好接收了吗?");
firstclientwrite.newLine();
firstclientwrite.flush();
// 经通道内的字节输入流进行一个封装程字符流,方便直接输出
BufferedReader testconnection = new BufferedReader(
new InputStreamReader(s.getInputStream()));
// 输出结果
String sss = testconnection.readLine();
System.out.println(sss);
//发送表名和列族名
firstclientwrite.write("nihao");
firstclientwrite.newLine();
firstclientwrite.flush();
//确定表发送是否成功
System.out.println(testconnection.readLine());
// 封装客户端的文本文件
BufferedReader clientread = new BufferedReader(new FileReader(
"file.json"));
// 准备将客户端的字符流写入到对应的通道内,OutputStreamWriter是将字符流转换成字节流,
// BufferedWriter封装字符流
BufferedWriter clientwirte = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
String line =
while ((line = clientread.readLine()) != null) {
clientwirte.write(line);
clientwirte.newLine();
clientwirte.flush();
// 提示发送完成
s.shutdownOutput();
// 准备接收一个反馈
// 经通道内的字节输入流进行一个封装程字符流,方便直接输出
BufferedReader ctread = new BufferedReader(new InputStreamReader(
s.getInputStream()));
// 输出结果
String fackcall =
while ((fackcall = ctread.readLine()) != null) {
System.out.println(fackcall);
// 释放资源
clientread.close();
s.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
2、服务端的代码:
(1)线程类的实现
package com.yiban.datacenter.ToHbaseFromJ
import java.io.BufferedR
import java.io.BufferedW
import java.io.IOE
import java.io.InputStreamR
import java.io.OutputStreamW
import java.net.S
import java.util.ArrayL
import java.util.L
import java.util.NavigableM
import java.util.Map.E
import net.sf.json.JSONA
import net.sf.json.JSONO
import org.apache.hadoop.conf.C
import org.apache.hadoop.hbase.HBaseC
import org.apache.hadoop.hbase.HColumnD
import org.apache.hadoop.hbase.HC
import org.apache.hadoop.hbase.HTableD
import org.apache.hadoop.hbase.MasterNotRunningE
import org.apache.hadoop.hbase.TableN
import org.apache.hadoop.hbase.ZooKeeperConnectionE
import org.apache.hadoop.hbase.client.A
import org.apache.hadoop.hbase.client.C
import org.apache.hadoop.hbase.client.ConnectionF
import org.apache.hadoop.hbase.client.HBaseA
import org.apache.hadoop.hbase.client.HT
import org.apache.hadoop.hbase.client.P
import org.apache.hadoop.hbase.client.R
import org.apache.hadoop.hbase.client.T
import org.apache.hadoop.hbase.util.B
public class UserThread implements Runnable {
private String testconnect = "我准备向你发送数据了,你准备好接收了吗?"; // 这个可以用来验证用户名和密码
private static Configuration conf = HBaseConfiguration.create();
private static Connection connection =
// 配置信息
conf.set(HConstants.ZOOKEEPER_QUORUM, "192.168.27.233");
conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181);
connection = ConnectionFactory.createConnection(conf);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
public UserThread(Socket s) {
private String userTableName =
private String columnFamilyName =
public void run() {
// TODO Auto-generated method stub
// 将通道内的字节流转换成字符流,并用bufferedreader进行封装,InputStreamReader是将字节流转换成字符流
BufferedReader serverread = new BufferedReader(
new InputStreamReader(s.getInputStream()));
// 询问客户端连接是否准备好,接受客户端的连接请求
String line = serverread.readLine(); // 阻塞
System.out.println(line);// 输出客户端的连接请求
// 将通道内的字符写入到对应的文件中,利用bufferedwrite进行封装,FileWriter是将字符流写入到文件中
BufferedWriter serverwrite = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
if (line.equals(testconnect)) {
serverwrite.write("连接成功,你可以发送数据了,发送数据前,请先发送你要用的数据库表名!");
serverwrite.newLine();
serverwrite.flush();
serverwrite.write("连接失败!");
serverwrite.newLine();
serverwrite.flush();
// 准备接收表名和列族名
userTableName = serverread.readLine();
System.out.println("tablename:" + userTableName);// 输出客户端的连接请求
// 告诉客户端,我接受成功
if (TableIsExist(userTableName)) {
serverwrite.write("接收表名成功");
serverwrite.newLine();
serverwrite.flush();
serverwrite.write("表不存在");
serverwrite.newLine();
serverwrite.flush();
// 循环读取客户端的数据
line = "";
StringBuffer temp = new StringBuffer(line);
while ((line = serverread.readLine()) != null) {
temp.append(line);
// 对json文件进行解析
JSONArray jsonArray = JSONArray.fromObject(temp.toString());
// 解析之后进行输出,在这里可以直接写入到hbase中
PrintJsonArray(jsonArray);
getAllTables(conf);
// 将接收到的数据写入hbase中的表中
insertData(jsonArray, userTableName);
// 给出一个反馈,提示数据上传成功
// 封装通道内的输出流,方便对他进行写字符数据
BufferedWriter bwserver = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
bwserver.write("文件上传成功!");
// bwserver.newLine();
bwserver.flush();
bwserver.close();
// 释放资源
// serverwrite.close();
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@SuppressWarnings("deprecation")
private void insertData(JSONArray jsonArray, String userTableName) {
// TODO Auto-generated method stub
Table table =
table = connection.getTable(TableName.valueOf(userTableName));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
List&Put& putlist = new ArrayList&Put&();
for (int i = 0; i & jsonArray.size(); i++) {
JSONObject jsonobject = jsonArray.getJSONObject(i);
Put put = new Put(Bytes.toBytes(jsonobject.getString("DocumentID")));// 指定行,也就是键值
// 参数分别:列族、列、值
put.add(Bytes.toBytes("info"),
Bytes.toBytes("DocumentContent"),
Bytes.toBytes(jsonobject.getString("DocumentContent")));
putlist.add(put);
table.put(putlist);
table.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
private boolean TableIsExist(String userTableName2) {
boolean flag =
// Connection connection = ConnectionFactory.createConnection(conf);
Admin ad = connection.getAdmin();
if (ad.tableExists(TableName.valueOf(userTableName2))) {
System.out.println("表存在");
System.out.println("表不存在");
} catch (Exception e) {
// TODO: handle exception
// TODO Auto-generated method stub
private void PrintJsonArray(JSONArray jsonArray) {
int size = jsonArray.size();
System.out.println("Size: " + size);
for (int i = 0; i & i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
System.out.println("[" + i + "]id=" + jsonObject.get("id"));
System.out.println("[" + i + "]name=" + jsonObject.get("name"));
System.out.println("[" + i + "]role=" + jsonObject.get("role"));
// create table
private void createTable(Configuration conf) {
// HBaseAdmin ha=new HBaseAdmin(conf);
// Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf(userTableName));
Admin ad = connection.getAdmin();
// TableName name= TableName.valueOf(Bytes.toBytes(tablename));//表名
HTableDescriptor desc = new HTableDescriptor(table.getName());
HColumnDescriptor family = new HColumnDescriptor(
Bytes.toBytes(columnFamilyName));// 列簇
desc.addFamily(family);
ad.createTable(desc);
ad.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
// Hbase获取所有的表信息
public static List getAllTables(Configuration conf)
throws MasterNotRunningException, ZooKeeperConnectionException,
IOException {
HBaseAdmin ad = new HBaseAdmin(conf);
List&String& tables =
if (ad != null) {
HTableDescriptor[] allTable = ad.listTables();
if (allTable.length & 0)
tables = new ArrayList&String&();
for (HTableDescriptor hTableDescriptor : allTable) {
tables.add(hTableDescriptor.getNameAsString());
System.out.println(hTableDescriptor.getNameAsString());
} catch (IOException e) {
e.printStackTrace();
// 按顺序输出
public void printResult(Result rs) {
if (rs.isEmpty()) {
System.out.println("result is empty!");
// new API and print Map of families to all versions of its qualifiers
// and values.
NavigableMap&byte[], NavigableMap&byte[], NavigableMap&Long, byte[]&&& temps = rs
.getMap();
String rowkey = Bytes.toString(rs.getRow()); // actain rowkey
System.out.println("rowkey-&" + rowkey);
for (Entry&byte[], NavigableMap&byte[], NavigableMap&Long, byte[]&&& temp : temps
.entrySet()) {
System.out.print("\tfamily-&" + Bytes.toString(temp.getKey()));
for (Entry&byte[], NavigableMap&Long, byte[]&& value : temp
.getValue().entrySet()) {
System.out.print("\tcol-&" + Bytes.toString(value.getKey()));
for (Entry&Long, byte[]& va : value.getValue().entrySet()) {
System.out.print("\tvesion-&" + va.getKey());
System.out.print("\tvalue-&"
+ Bytes.toString(va.getValue()));
System.out.println();
&(2)主函数的实现
package com.yiban.datacenter.ToHbaseFromJ
import java.io.IOE
import java.net.ServerS
import java.net.S
import org.apache.hadoop.conf.C
import org.apache.hadoop.hbase.HBaseC
import org.apache.hadoop.hbase.HC
public class HbaseServer {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
ServerSocket ss=new ServerSocket(22222);
while(true){
Socket s=ss.accept();
new Thread(new UserThread3(s)).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
阅读(...) 评论()
随笔: 170温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
我机器上已经安装好了&thrift-0.9.1二、示例编辑demo.thrift文件,内容如下:struct&UserProfile{&&&&&&&&1:i32&id,&//注意这里是逗号,而不是分号&&&&&&&&2:string&name,&&&&&&&&3:string&blurb} //这里没有分号&service&UserStorage{&&&&&&&&void&store(1:&UserProfile&user),&//注意这里是逗号,而不是分号&&&&&&&&UserProfile&getUser(1:&i32&uid)}&运行如下命令cloud1:~/test/thrift/demo # thrift -r --gen cpp demo.thrift&cloud1:~/test/thrift/demo # lsdemo.thrift &gen-cpp可以看到在当前目录下产生了一个gen-cpp的目录,该目录下即以上命令产生的文件:UserStorage.cppUserStorage.hUserStorage_server.skeleton.cppdemo_constants.cppdemo_constants.hdemo_types.cppdemo_types.h注意:在以上文件中,只有UserStorage_server.skeleton.cpp是跟业务相关的,是可以修改的,其余文件都是框架相关的。UserStorage_server_skeleton.cpp文件内容如下:&// This autogenerated skeleton file illustrates how to build a server.// You should copy it to another filename to avoid overwriting it.&#include "UserStorage.h"#include &protocol/TBinaryProtocol.h&#include &server/TSimpleServer.h&#include &transport/TServerSocket.h&#include &transport/TBufferTransports.h&#include &map&&using namespace ::apache::using namespace ::apache::thrift::using namespace ::apache::thrift::using namespace ::apache::thrift::&using boost::shared_&class UserStorageHandler : virtual public UserStorageIf {&public:& UserStorageHandler() {&&& // Your initialization goes here& }&& void store(const UserProfile& user) {&&& // Your implementation goes here&&& printf("store\n");& }&& void getUser(UserProfile& _return, const int32_t uid) {&&& // Your implementation goes here&&& printf("getUser\n");& }};&int main(int argc, char **argv) {& int port = 9090;& shared_ptr&UserStorageHandler& handler(new UserStorageHandler());& shared_ptr&TProcessor& processor(new UserStorageProcessor(handler));& shared_ptr&TServerTransport& serverTransport(new TServerSocket(port));& shared_ptr&TTransportFactory& transportFactory(new TBufferedTransportFactory());& shared_ptr&TProtocolFactory& protocolFactory(new TBinaryProtocolFactory());&& TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);& server.serve();& return 0;}可以看到,该文件只是一个框架,用户可以根据需要扩展该文件,笔者修改如下(蓝色部分为添加的代码,同时将文件改名为UserStorage_server.cpp)://&This&autogenerated&skeleton&file&illustrates&how&to&build&a&server.//&You&should&copy&it&to&another&filename&to&avoid&overwriting&it.#include&"UserStorage.h"#include&&protocol/TBinaryProtocol.h&#include&&server/TSimpleServer.h&#include&&transport/TServerSocket.h&#include&&transport/TBufferTransports.h&#include&&map&using&namespace&using&namespace&::apache::using&namespace&::apache::thrift::using&namespace&::apache::thrift::using&namespace&::apache::thrift::using&boost::shared_class&UserStorageHandler&:&virtual&public&UserStorageIf&{&public:&&UserStorageHandler()&{&&&&//&Your&initialization&goes&here&&}&&void&store(const&UserProfile&&user)&{&&&&//&Your&implementation&goes&here& & log[user.id]&=&&//实际的保存操作&&&&printf("store\n");&&}&&void&getUser(UserProfile&&_return,&const&int32_t&uid)&{&&&&//&Your&implementation&goes&here&&&&&&&&_return&=&log[uid];&//实际获取操作,注意:在实际生产中,这里还需要异常处理&&&&printf("getUser\n");&&}&&//增加成员变量,用户保存用户数据,为了简单起见,这里只将数据保存在内存,当然可以可以保存在数据库、文件等等,主要注意,如果保存在其他介质的话& //在初始化的时候记得加载进内存或者打开访问句柄&&protected:&&&&&&&&map&int32_t,&UserProfile&&};int&main(int&argc,&char&**argv)&{&&int&port&=&9090;&&shared_ptr&UserStorageHandler&&handler(new&UserStorageHandler());&&shared_ptr&TProcessor&&processor(new&UserStorageProcessor(handler));&&shared_ptr&TServerTransport&&serverTransport(new&TServerSocket(port));&&shared_ptr&TTransportFactory&&transportFactory(new&TBufferedTransportFactory());&&shared_ptr&TProtocolFactory&&protocolFactory(new&TBinaryProtocolFactory());&&TSimpleServer&server(processor,&serverTransport,&transportFactory,&protocolFactory);&&server.serve();&&return&0;}可以看到以上程序还包括一个简单的服务端代码,问了进行测试,笔者从thrift/tutorial/cpp/目录下copy了一个客户端代码和Makefile修改如下:CppClient.cpp (蓝色部分为客户化代码)&&#include&&stdio.h&#include&&unistd.h&#include&&sys/time.h&#include&&protocol/TBinaryProtocol.h&#include&&transport/TSocket.h&#include&&transport/TTransportUtils.h&#include&"UserStorage.h"using&namespace&using&namespace&apache::using&namespace&apache::thrift::using&namespace&apache::thrift::using&namespace&int&main(int&argc,&char**&argv)&{&&shared_ptr&TTransport&&socket(new&TSocket("localhost",&9090));&&shared_ptr&TTransport&&transport(new&TBufferedTransport(socket));&&shared_ptr&TProtocol&&protocol(new&TBinaryProtocol(transport));&&UserStorageClient&client(protocol);&&try&{&&&&transport-&open();&&&&&&&&UserProfile&&&&&&&&&user.id&=&1;&&&&&&&&user.name&=&"liqb";&&&&&&&&user.blurb&=&"aaaaaa";&&&&&&&&client.store(user);&&&&&&&&UserProfile&user2;&&&&&&&&client.getUser(user2,&1);&&&&&&&&printf("user.id&=&%d&user.name&=&%s&user.blurb&=&%s\n",&user2.id,&user2.name.c_str(),&user2.blurb.c_str());&&&&transport-&close();&&}&catch&(TException&&tx)&{&&&&printf("ERROR:&%s\n",&tx.what());&&}}&Makefile&BOOST_DIR&=&/usr/local/boost/include/boost-1_33_1/THRIFT_DIR&=&/usr/local/include/thriftLIB_DIR&=&/usr/local/libGEN_SRC&=&UserStorage.cpp&demo_constants.cpp&demo_types.cppdefault:&server&clientserver:&UserStorage_server.cpp&&&&&&&&g++&-o&CppServer&-I${THRIFT_DIR}&-I${BOOST_DIR}&&-I../gen-cpp&-L${LIB_DIR}&-lthrift&UserStorage_server.cpp&${GEN_SRC}client:&CppClient.cpp&&&&&&&&g++&-o&CppClient&-I${THRIFT_DIR}&-I${BOOST_DIR}&&-I../gen-cpp&-L${LIB_DIR}&-lthrift&CppClient.cpp&${GEN_SRC}clean:&&&&&&&&$(RM)&-r&CppClient&CppServer&编译之后产生CppServer 和CppClient 两个可执行程序,分别运行CppServer 和CppClient,即可以看到测试结果。先运行服务器:cloud1:~/test/thrift/demo/gen-cpp # ./CppServer&再执行客户端:cloud1:~/test/thrift/demo/gen-cpp # ./CppClient&user.id = 1 user.name = liqb user.blurb = aaaaaacloud1:~/test/thrift/demo/gen-cpp #&服务器上显示:cloud1:~/test/thrift/demo/gen-cpp # ./CppServer&storegetUserPython 版客户端:thrift/tutorial/下拷:PythonClient.py 略做修改:cloud1:~/test/thrift/demo # vi PythonClient.py&& 1 #!/usr/bin/env python& 2&& 3 #& 4 # Licensed to the Apache Software Foundation (ASF) under one& 5 # or more contributor license agreements. See the NOTICE file#!/usr/bin/env python## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## & http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#import sys, globsys.path.append('gen-py')#sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])from demo import UserStorage&from demo.ttypes import *from thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocoltry:& & # Make socket& & transport = TSocket.TSocket('localhost', 9090)& & # Buffering is critical. Raw sockets are very slow& & transport = TTransport.TBufferedTransport(transport)& & # Wrap in a protocol& & protocol = TBinaryProtocol.TBinaryProtocol(transport)& & # Create a client to use the protocol encoder& & client = UserStorage.Client(protocol)& & # Connect!& & transport.open()& & try:& & & & u1 = UserProfile() && & & & u1.id=456 && & & & u1.name='nick' && & & & u1.blurb='test bbb' && & & & client.store(u1)&& & & & print 'store done!'& & except InvalidOperation, io:&& & & & print 'InvalidOperation: %r' % io& & u = client.getUser(123) && & print 'id=%s name=%s blurb=%s' %(u.id,u.name,u.blurb)& & # Close!& & transport.close()except Thrift.TException, tx:& & print '%s' % (tx.message)cloud1:~/test/thrift/demo # python PythonClient.py&store done!id=123 name=jason blurb=test aaacloud1:~/test/thrift/demo #&Java 版客户端:thrift-0.9.1/tutorial/java/src/&下拷:JavaClient.java&做修改:重命名为:UserProfileClient.javacloud1:~/test/thrift/demo # vi UserProfileClient.java&import org.apache.thrift.TEimport org.apache.thrift.transport.TSSLTransportFimport org.apache.thrift.transport.TTimport org.apache.thrift.transport.TSimport org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportPimport org.apache.thrift.protocol.TBinaryPimport org.apache.thrift.protocol.TPpublic class UserProfileClient {& public static void main(String [] args) {& & /*if (args.length != 1) {& & & System.out.println("Please enter 'simple' or 'secure'");& & & System.exit(0);& & } &*/&& & try {& & & TT& & & //if (args[0].contains("simple")) {& & & & transport = new TSocket("localhost", 9090);& & & & transport.open();& & & //} &&& & & //else {& & & & /* && & & & &* Similar to the server, you can use the parameters to setup client parameters or& & & & &* use the default settings. On the client side, you will need a TrustStore which& & & & &* contains the trusted certificate along with the public key.&& & & & &* For this example it's a self-signed cert.&& & & & &*/& & & & //TSSLTransportParameters params = new TSSLTransportParameters();& & & & //params.setTrustStore("../../lib/java/test/.truststore", "thrift", "SunX509", "JKS");& & & & /* && & & & &* Get a client transport instead of a server transport. The connection is opened on& & & & &* invocation of the factory method, no need to specifically call open()& & & & &*/& & & & //transport = TSSLTransportFactory.getClientSocket("localhost", 9091, 0, params);& & & //} &&& & & TProtocol protocol = new &TBinaryProtocol(transport);& & & UserStorage.Client client = new UserStorage.Client(protocol);& & & int uid=123;& & & System.out.println(client.getUser(uid));& & & UserProfile u = new UserProfile();& & & u.id=999;& & & u.name="kaining";& & & u.blurb="test 999";&& & & client.store(u);& & & transport.close();& & } catch (TException x) {& & & x.printStackTrace();& & } &&& }}cloud1:~/test/thrift/demo # cat compile.sh&#!/bin/shexport CLASS_PATH_JAVA=""for i in /usr/local/lib/*.jardo& & & & if [ "x${CLASS_PATH_JAVA}" == "x" ]& & & & then& & & & & & & & export CLASS_PATH_JAVA=$i& & & & & & & & continue& & & & fi& & & & export CLASS_PATH_JAVA=${CLASS_PATH_JAVA}:$i#echo $idoneecho "$CLASS_PATH_JAVA"javac -classpath $CLASS_PATH_JAVA UserProfileClient.java ./gen-java/*.javacloud1:~/test/thrift/demo #&cloud1:~/test/thrift/demo # cat run.sh&#!/bin/shexport CLASS_PATH_JAVA=""for i in /usr/local/lib/*.jardo& & & & if [ "x${CLASS_PATH_JAVA}" == "x" ]& & & & then& & & & & & & & export CLASS_PATH_JAVA=.:$i& & & & & & & & continue& & & & fi& & & & export CLASS_PATH_JAVA=${CLASS_PATH_JAVA}:$idone#echo "$CLASS_PATH_JAVA"java -cp $CLASS_PATH_JAVA:./gen-java UserProfileClientcloud1:~/test/thrift/demo #&编译,执行compile.shcloud1:~/test/thrift/demo # ./compile.sh&/usr/local/lib/commons-codec-1.6.jar:/usr/local/lib/commons-lang3-3.1.jar:/usr/local/lib/commons-logging-1.1.1.jar:/usr/local/lib/httpclient-4.2.5.jar:/usr/local/lib/httpcore-4.2.4.jar:/usr/local/lib/junit-4.4.jar:/usr/local/lib/libthrift-0.9.1-javadoc.jar:/usr/local/lib/libthrift-0.9.1.jar:/usr/local/lib/log4j-1.2.14.jar:/usr/local/lib/servlet-api-2.5.jar:/usr/local/lib/slf4j-api-1.5.8.jar:/usr/local/lib/slf4j-log4j12-1.5.8.jarNote: Some input files use unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.cloud1:~/test/thrift/demo #运行,执行run.shcloud1:~/test/thrift/demo # ./run.sh&UserProfile(id:123, name:jason, blurb:test aaa)cloud1:~/test/thrift/demo #&参考:
阅读(6408)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'thrift C++做server, C++,python, java做Client例子',
blogAbstract:'一、安装我机器上已经安装好了&thrift-0.9.1二、示例编辑demo.thrift文件,内容如下:',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:1,
publishTime:3,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 python client server 的文章

 

随机推荐