我正试图用 Tokio 弄湿我的脚。当我从 Telnet 连接发送消息时,我得到Custom { kind: InvalidData, error: FrameTooBig }
. 我不明白这个问题,也不知道如何克服它。
extern crate tokio;
extern crate tokio_io;
use tokio::io;
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio_io::codec::length_delimited;
fn main() {
let addr = "127.0.0.1:12345".parse().unwrap();
let listener = TcpListener::bind(&addr).unwrap();
let server = listener
.incoming()
.for_each(|socket| {
let transport = length_delimited::Builder::new().new_read(socket);
let msg_proccessing = transport
.for_each(|msg| {
// Note: This part is never actually executed
println!("{:?}", msg);
Ok(())
})
.map_err(|e| println!("waaaaaaaaaaaaaaaaa {:?}", e));
tokio::spawn(msg_proccessing);
Ok(())
})
.map_err(|_| {});
tokio::run(server);
}
客户端:
▶ telnet localhost 12345
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
\x00\x00\x00\x0bhello world
Connection closed by foreign host.