3
有人能帮助我吗?Python:发送请求到protobuf服务器
我有一个.proto文件。
如何从客户端发送和打印请求到套接字服务器? 如何对客户做出回应?
protofile:
option optimize_for = SPEED;
option java_package = "org.epicsquad.protofile.proto";
package protofile.proto;
enum CommandTypeEnum {
COMMAND_one = 0;
COMMAND_two = 1;
COMMAND_three = 2;
}
enum ResultTypeEnum {
RESULT_ONE = 0;
RESULT_TWO = 1;
message Result {
required uint32 result_one = 1;
optional string result_two = 2;
}
message Request {
optional string req1 = 1;
optional string req2 = 2;
}
message Response {
required string resp1 = 1;
required string resp2 = 2;
}
服务器:
import sys
sys.path.append('../../main')
import protobuf.socketrpc.server as server
server = server.SocketRpcServer(8090)
print 'Serving on port 8090'
server.run()
客户端:
import sys
sys.path.append('../../main')
import protofile_pb2
from protobuf.socketrpc import RpcService
import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
hostname = 'localhost'
port = 8090
request = protofile_pb2.Request()
我有一个HelloWorld示例,但有发送请求通过服务去。但是我的.protofile中没有服务消息。 谢谢!!!