Golang
PackageMainImport ( "FMT" "Git.apache.org/thrift.git/lib/go/thrift" "Net" "Thriftproxy" "Time") Type thriftclient struct {client*Thriftproxy. Thriftproxyclient Transport*Thrift. Tsocket}func (c*thriftclient) Newthriftclient () {//ThriftTransportfactory: =Thrift. Newtframedtransportfactory (Thrift. Newttransportfactory ()) Protocolfactory:=Thrift. Newtbinaryprotocolfactorydefault () var er error c.transport, er=Thrift. Newtsocket (NET. Joinhostport (Thrift_host, Thrift_port)) c.transport.settimeout (TIMEOUT*Time . Second)ifEr! =Nil {panic (FMT. Sprintf ("Error Resolving Address:%v", er)) } Usetransport:=Transportfactory.gettransport (c.transport) c.client=Thriftproxy. Newthriftproxyclientfactory (Usetransport, protocolfactory)ifERR: = C.transport.open (); Err! =Nil {panic (FMT. Sprintf ("Error opening Socket:%v", err)) }}func (c*thriftclient) Close () {c.transport.close ()}
New (thriftclient) thriftclient. Newthriftclient () defer thriftclient. Close () detailrequest:new(SE. detailrequest) =178236
= Thriftclient.client.SearchDetailRtsSync (detailrequest)
Php
?PHPHeader("content-type:text/html; Charset=utf-8 " ); $GLOBALS[' thrift_root '] =dirname(__file__). '/thrift '; require_once dirname(__file__).‘ /thrift.php '; require_once $GLOBALS[' Thrift_root ']. ' /protocol/tbinaryprotocol.php '; require_once $GLOBALS[' Thrift_root ']. ' /transport/tsocket.php '; require_once $GLOBALS[' Thrift_root ']. ' /transport/thttpclient.php '; require_once $GLOBALS[' Thrift_root ']. ' /transport/tbufferedtransport.php '; require_once $GLOBALS[' Thrift_root ']. ' /transport/tframedtransport.php '; require_once $GLOBALS[' Thrift_root ']. ' /type/ttype.php '; require_once $GLOBALS[' Thrift_root ']. ' /type/tmessagetype.php '; require_once $GLOBALS[' Thrift_root ']. ' /factory/tstringfuncfactory.php '; require_once $GLOBALS[' Thrift_root ']. ' /stringfunc/tstringfunc.php '; require_once $GLOBALS[' Thrift_root ']. ' /stringfunc/core.php '; require_once $GLOBALS[' Thrift_root ']. ' /base/tbase.php '; require_once $GLOBALS[' Thrift_root ']. ' /exception/texception.php '; require_once $GLOBALS[' Thrift_root ']. ' /exception/tprotocolexception.php '; require_once $GLOBALS[' Thrift_root ']. ' /exception/ttransportexception.php '; require_once $GLOBALS[' Thrift_root ']. ' /exception/tapplicationexception.php '; //error_reporting (E_none); $GEN _dir= './gen-php '; require_once $GEN _dir.‘ /thriftproxy.php '; require_once $GEN _dir.‘ /types.php '; error_reporting(E_all); $socket=NewThrift\transport\tsocket (' 127.0.0.1 ', 5101); $socket->setdebug (true); //set receive timeout (milliseconds) $socket->setsendtimeout (10000); $socket->setrecvtimeout (20000); $transport=NewThrift\transport\tframedtransport ($socket);//the supported data transfer methods depend on the server-side usage mode and the server's settings $protocol=NewThrift\protocol\tbinaryprotocol ($transport);//Supported transport Formats Select the transport layer, which is the same as the server settings $client=NewThriftproxyclient ($protocol); $transport-open (); Try{ $ListRequest=Newlistrequest (); $ListRequest->check_in_date=Strtotime(' 2014-07-20 '); $ListRequest->check_out_date=Strtotime(' 2014-07-21 '); $ListRequest->region_id= ' 178236 '; $ListRequest->rank_type=ranktype::Priceasc; $ListRequest->hotel_star=Array(Hotelstartype::star4,hotelstartype::STAR3); $PageInfo=NewPageInfo (); $PageInfo->page_no=1; $PageInfo->page_size=50; $ListRequest->page_info=$PageInfo; $a=$client->searchlist ($ListRequest); Var_dump($a); } Catch(texception$tx) { Print' Texception: '.$tx->getmessage (). " /n "; } $transport-Close (); ?>
Python
#!/usr/bin/env python#-*-coding:utf-8-*-Importsys sys.path.append ('gen-py') Sys.path.append ('Thrift') fromThriftproxyImportThriftproxy fromSe.ttypesImport* fromThriftImportThrift fromThrift.transportImportTsocket fromThrift.transportImportTtransport fromThrift.protocolImportTbinaryprotocolImport TimeTry: Socket= Tsocket.tsocket ('127.0.0.1', 5101) Transport=Ttransport.tframedtransport (socket) Protocol=Tbinaryprotocol.tbinaryprotocol (transport) Client=thriftproxy.client (Protocol) Transport.open () Request=listrequest () request.check_in_date=time.time (+86400)request.check_out_date=time.time () +86400*2request.region_id=178236Response=client. SearchList (Request)PrintResponse Transport.close ()exceptThrift.texception, TX:Print "%s"% (Tx.message)
Thrift fetching python PHP go client code