【问题标题】:Python: sending request to the protobuf serverPython:向 protobuf 服务器发送请求
【发布时间】:2014-10-26 23:16:17
【问题描述】:

有人可以帮帮我吗?

我有一个 .proto 文件。

如何从客户端向套接字服务器发送和打印请求? 如何回复客户?

原型文件:

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 示例,但是通过 SERVICE 发送请求。但是我的 .protofile 中没有服务消息。 谢谢!!!

【问题讨论】:

    标签: python protocol-buffers rpc proto


    【解决方案1】:

    在您的 .proto 文件中添加 option py_generic_services = true; 这一行。 如果不这样做,protoc 将不会生成 rpc 所需的存根

    【讨论】:

      猜你喜欢
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2018-10-04
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多