写入websocket流

问题描述

我正在使用tungstenite from this example并使用write.send from there

连接到Websocket服务器
let connect_addr = env::args()
    .nth(1)
    .unwrap_or_else(|| panic!("this program requires at least one argument"));

let url = url::Url::parse(&connect_addr).unwrap();

let (stdin_tx,stdin_rx) = futures_channel::mpsc::unbounded();
tokio::spawn(read_stdin(stdin_tx));

let (ws_stream,_) = connect_async(url).await.expect("Failed to connect");
println!("WebSocket handshake has been successfully completed");

let (write,read) = ws_stream.split();

## THIS DOESNT WORK ###
write.send(Message::Text(format!("{}","HELLO!")))
            .await
            .expect("Failed to send message");

我无法使写入工作。我得到:

error[E0599]: no method named `send` found for struct `futures_util::stream::stream::split::SplitSink<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream,tokio_native_tls::TlsStream<tokio::net::tcp::stream::TcpStream>>>,tungstenite::protocol::message::Message>` in the current scope
   --> src/main.rs:28:15
    |
28  |         write.send(Message::Text(format!("{}",8)))
    |               ^^^^ method not found in `futures_util::stream::stream::split::SplitSink<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream,tungstenite::protocol::message::Message>`
    |
   ::: ../futures-util-0.3.5/src/sink/mod.rs:207:8
    |
207 |     fn send(&mut self,item: Item) -> Send<'_,Self,Item>
    |        ----
    |        |
    |        the method is available for `std::boxed::Box<futures_util::stream::stream::split::SplitSink<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream,tungstenite::protocol::message::Message>>` here
    |        the method is available for `std::sync::Arc<futures_util::stream::stream::split::SplitSink<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream,tungstenite::protocol::message::Message>>` here
    |        the method is available for `std::rc::Rc<futures_util::stream::stream::split::SplitSink<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream,tungstenite::protocol::message::Message>>` here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...