我想将 C# 客户端应用程序与 Java 服务器应用程序通信。Java 使用带有 protobuf 管道编码器的 Netty 框架。
我的原型文件:导入“google/protobuf/csharp_options.proto”;
option (google.protobuf.csharp_file_options).namespace = "ChatClient.LoginProtocol";
option (google.protobuf.csharp_file_options).umbrella_classname = "LoginProtocol";
option optimize_for = SPEED;
message Credential {
required string email = 1;
required string password = 2;
}
Netty 管道编解码器:
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
p.addLast("protobufDecoder", new ProtobufDecoder(LoginProtos.Credential.getDefaultInstance()));
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
p.addLast("protobufEncoder", new ProtobufEncoder());
那么如何将消息发送到 java Server。c#代码:
stream = client.GetStream();
sReader = new StreamReader(stream);
sWriter = new StreamWriter(stream);
Credential.Builder builder = Credential.CreateBuilder();
builder.SetEmail("xxx@gmail.com").SetPassword("12356");
sWriter.Write(builder.Build().ToByteArray());
sWriter.Flush();
感谢您的帮助,对不起我的英语。