环境:Python 3.6.2 Thrift 0.9.3
客户端代码:
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from message.api import MessageService
from io import *
__HOST = 'localhost'
__PORT = 8800
b = StringIO()
tsocket = TSocket.TSocket(__HOST, __PORT)
transport = TTransport.TBufferedTransport(tsocket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MessageService.Client(protocol)
client.send_sendEmailMessage()
transport.open()
服务端代码:
from message.api import MessageService
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
class MessageServiceHandler:
def sendMobileMessage(self):
print("sendMobileMessage")
return True
def sendEmailMessage(self):
print("sendEmailMessage")
return True
if __name__ == "__main__":
handler = MessageServiceHandler()
processor = MessageService.Processor(handler)
transport = TSocket.TServerSocket("localhost", 8800)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print("python thrift server start")
server.serve()
print("python thrift server exit")
客户端调用报错:
