文件名称:Rust 的轻量级基于流的 WebSocket 实现。
文件大小:444KB
文件格式:ZIP
更新时间:2024-07-18 12:14:37
rust websockets
钨矿Rust 的轻量级基于流的 WebSocket 实现。use std:: net:: TcpListener;use std:: thread:: spawn;use tungstenite:: server:: accept;/// A WebSocket echo serverfnmain () {let server= TcpListener::bind ("127.0.0.1:9001" ).unwrap ();for streamin server.incoming () {spawn (move|| {letmut websocket=accept (stream.unwrap ()).unwrap ();loop {let msg= websocket.read_message ().unwrap ();// We do not want to send back ping/pong messages.if msg.is_binary ()|| msg.is_text () { websocket.write_message (