我正在为客户机-服务器应用程序尝试GRPC-Swift。我正在使用GRPC对客户端和服务器客户端都是一个iPhone应用程序,我用iPhone模拟器进行了尝试。
我跟踪了这个客户端流RPC的链接。当我从客户端向服务器发送消息时,我从服务器收到控制台中的以下错误消息,
error io.grpc.server_channel_call : unable to determine http version中的服务器。
HTTPProtocolSwitcher.swift
在函数func channelRead(context: ChannelHandlerContext, data: NIOAny)中,它正在检查是否为HTTPProtocolVersion,并且它丢失了。
如何从客户端代码发送HTTPVersion?
更新:
客户代码
import GRPC
import NIO
class HTTPClient {
private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
private var channel: ClientConnection?
private var client: ChatGuide_ChatGuideClient?
private var clientCall: ClientStreamingCall<ChatGuide_TextMessage, ChatGuide_TextMessage>?
func connect(host: String, port: Int) throws {
let channel = ClientConnection.secure(group: self.group)
.connect(host: host, port: port)
self.channel = channel
self.client = ChatGuide_ChatGuideClient(channel: channel)
}
func disconnect() {
do {
self.clientCall?.sendEnd(promise: nil)
_ = try self.clientCall?.status.wait()
try self.group.syncShutdownGracefully()
} catch let error {
print("\(type(of: self)): Could not shutdown gracefully -", error.localizedDescription)
}
}
func initiateClient() {
let timeAmount = TimeAmount.minutes(1)
let timeLimit = TimeLimit.timeout(timeAmount)
let options = CallOptions(timeLimit: timeLimit)
let call = self.client?.chat(callOptions: options)
call?.response.whenSuccess { (message) in
print("\(type(of: self)): Message from server -", message.text)
}
call?.response.whenFailure { (error) in
print("\(type(of: self)): Response error -", error.localizedDescription)
}
self.clientCall = call
}
func send(text: String) {
if self.clientCall == nil {
self.initiateClient()
}
let message = ChatGuide_TextMessage.with {
$0.text = text
}
self.clientCall?.sendMessage(message, promise: nil)
}
}发布于 2020-07-17 15:04:58
嘿维格尼什
我目前正在学习gRPC-斯威夫特本人,所以我希望我将是服务,而不是更糟的事情。
但是,在我看来,如果您查看HTTP1ToGRPCServerCodec.swift文件这里,就不会为了传输Protobuf数据包而配置HTTP/1.x层。
我想你会对如何调整你的代码有一个更清晰的认识,很抱歉,我不能提供更多的细节,但是如果不进一步测试和检查代码基,我就不能太确定自己了。
向我问好,如果我真的很有帮助的话,随时通知我,
干杯
发布于 2020-07-18 06:34:00
我在服务器上启动了不安全的服务器,
let server = Server.insecure(group: self.group)我从客户端启动了安全ClientConnection,
let channel = ClientConnection.secure(group: self.group)我从这里那里得到了澄清,所以我让ClientConnection也不安全,
let channel = ClientConnection.insecure(group: self.group)在这之后,它现在起作用了。
https://stackoverflow.com/questions/62936926
复制相似问题