コード例 #1
0
ファイル: hello_client.py プロジェクト: lxlenovostar/coursera
import sys
sys.path.append("gen-py")
from hello import HelloSvc

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

trans_ep = TSocket.TSocket("localhost", 9095)
trans_buf = TTransport.TBufferedTransport(trans_ep)
proto = TBinaryProtocol.TBinaryProtocol(trans_buf)
client = HelloSvc.Client(proto)

trans_ep.open()
msg = client.hello_func()
print("[Client] received: %s" % msg)
コード例 #2
0
ファイル: httpServer.py プロジェクト: P79N6A/php
import sys
sys.path.append('gen-py')

from hello import HelloSvc
from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer


class HelloSvcHandler:
    def hello_func(self):
        print "Hello Called"
        return "hello from Python"


processor = HelloSvc.Processor(HelloSvcHandler())
protoFactory = TJSONProtocol.TJSONProtocolFactory()
port = 9090
server = THttpServer.THttpServer(processor, ("localhost", port), protoFactory)
print "Python server running on port " + str(port)
server.serve()
コード例 #3
0
import sys
sys.path.append('gen-py')
from hello import HelloSvc
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer


class HelloHandler:
    def hello_func(self):
        print("[Server] handler")
        return "Hello from python server"


handler = HelloHandler()
proc = HelloSvc.Processor(handler)

trans_svr = TSocket.TServerSocket(port=9090)
trans_fac = TTransport.TBufferedTransportFactory()
proto_fac = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(proc, trans_svr, trans_fac, proto_fac)
server.serve()