- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在弄清楚如何使用 tokio-proto
crate,特别是在建立连接时进行的握手。我从 official documentation 中得到了示例工作:
impl<T: AsyncRead + AsyncWrite + 'static> ClientProto<T> for ClientLineProto {
type Request = String;
type Response = String;
/// `Framed<T, LineCodec>` is the return value of `io.framed(LineCodec)`
type Transport = Framed<T, line::LineCodec>;
type BindTransport = Box<Future<Item = Self::Transport, Error = io::Error>>;
fn bind_transport(&self, io: T) -> Self::BindTransport {
// Construct the line-based transport
let transport = io.framed(line::LineCodec);
// Send the handshake frame to the server.
let handshake = transport.send("You ready?".to_string())
// Wait for a response from the server, if the transport errors out,
// we don't care about the transport handle anymore, just the error
.and_then(|transport| transport.into_future().map_err(|(e, _)| e))
.and_then(|(line, transport)| {
// The server sent back a line, check to see if it is the
// expected handshake line.
match line {
Some(ref msg) if msg == "Bring it!" => {
println!("CLIENT: received server handshake");
Ok(transport)
}
Some(ref msg) if msg == "No! Go away!" => {
// At this point, the server is at capacity. There are a
// few things that we could do. Set a backoff timer and
// try again in a bit. Or we could try a different
// remote server. However, we're just going to error out
// the connection.
println!("CLIENT: server is at capacity");
let err = io::Error::new(io::ErrorKind::Other, "server at capacity");
Err(err)
}
_ => {
println!("CLIENT: server handshake INVALID");
let err = io::Error::new(io::ErrorKind::Other, "invalid handshake");
Err(err)
}
}
});
Box::new(handshake)
}
}
但是官方文档只提到了没有状态信息的握手。有没有一种通用的方法可以从握手中检索和存储有用的数据?
例如,如果在握手过程中(在建立连接后的第一条消息中)服务器发送了一些稍后应该由客户端使用的 key ,ClientProto
实现应该如何查看该 key key ?它应该存储在哪里?
最佳答案
您可以将字段添加到 ClientLineProto
,所以这应该有效:
pub struct ClientLineProto {
handshakes: Arc<Mutex<HashMap<String, String>>>
}
然后您可以引用它并根据需要存储数据:
let mut handshakes = self.handshakes.lock();
handshakes.insert(handshake_key, "Blah blah handshake data")
这种访问可以在 bind_transport()
中用于存储内容。然后,当您在 main()
函数中创建 Arc::Mutex::HashMap
时,您将可以访问 serve()< 中的所有内容
方法,这意味着您可以将它传递给服务对象实例化,然后握手将在 call()
期间可用。
关于rust - 如何从 tokio-proto 连接握手中检索信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245753/
专家: 我有两个 .proto 文件(如下所示),第二个依赖于第一个。 ImageMessage.proto: package dvr; message ImageMessage { re
我按照找到的例子 here .但是每当我输入命令“C:/Program Files/protoc/bin/protoc”object_detection/protos/.proto --python_
我有一个名为 myProtos 的库,它看起来像这样 . |-- proto |---- hello.proto | |-- generated └---- hello.pb.go 我在外部有一个名为
我想知道如何正确引用外部原型(prototype)文件。假设我有一个引用标准 protobuf 类型的 .proto 文件,例如 Timestamp : syntax = "proto3"; pack
我是 Google Protobuf 新手。我想解决一个问题,但在互联网上找不到答案,也许我问错了问题.. 我想构建一个使用 .proto 模式(和生成的类)的工具,并将输入字符串从可读字符串转换为
我有这个问题: grpc_tools._protoc_compiler.ProtocErrors: google/protobuf/timestamp.proto:-1:0 error: File n
软件环境:Win10,Goland。 去版本:go1.9.1 windows/amd64.协议(protocol)——版本:libprotoc 3.5.1当我执行命令时。结果如下 protoc -I
我正在使用 Android Studio 来处理 tomahawk-android项目,所以我使用 git 将该项目直接克隆到 Android Studio 中,但无法构建,并显示; Could no
一 点睛 可以在 proto 中定义多个类,然后从中选择任意一个类,可以在 proto 中定义多个 message,然后再将多个 message 以枚举的形式供使用时选择。 二 实战 1 proto
我在不同的 go 包下编译了 2 个 proto,但是当我在服务器中注册它们并运行它时,我得到: panic: proto: file "common.proto" is already regist
perl6 如何决定哪个 proto token先匹配? 下面的代码按预期工作,它匹配字符串 1234 , 和 Grammar::Tracer显示匹配的第一个标记是 s:sym ,这是有道理的,因为它
我有 2 个 grpc 服务( service1 和 service2 ),它们相互交互,在某些情况下,service1 的 rpc 响应will 由 service2 中定义的结构组成,在经历了不可
我有一个 MyResponse.proto 文件,它导入两个 .proto 文件 Alternative.proto 和 Index.proto >. MyResponse.proto 文件: imp
我有一个非常简单的 android 应用程序,它使用 protobuf 从服务器获取数据,然后让用户浏览数据树(简化) 现在我只想在我的结构中使用这些数据,所以我使用 protobuf 回复(通过自动
我有两个服务:Story 和 Tag。这些文件的结构如下: Story |-- StoryService | `-- proto | `-- storyservice.proto `-
对于 CPP 编程,我在 .proto 文件中定义了一个 enum,我必须在另一个 .proto 文件中使用相同的枚举。 //first.proto package A; enum foo {
如果 protobuf 消息中的属性是第一个成员或第二个成员,有什么区别? 我拥有的 Request proto 消息有 2 个字段。我被要求交换属性的位置 message SomeRequest {
我正在使用 protobuf-net 的 ProtoBufTool 自定义工具从 .proto 文件生成 C# 类。到目前为止,我一直无法让原型(prototype)文件中的 import 语句使用相
我正在从事 AI 项目,但我在 Python 方面仍然不是很有经验。 我正在尝试 build and test this project . 我遵循了所有说明,但是当我尝试启动 python 脚本时仍
我有一个名为 Game 的对象,它具有名称、编号、团队等属性。它的许多属性本身就是对象:团队是团队对象的列表。例如,所有这些对象都具有使用 proto 定义的函数(不确定实际术语) Game.prot
我是一名优秀的程序员,十分优秀!