make echo server compile

The original code failed to compile with "expected item after doc comment" error message
pull/134/head
Zoldszemesostoros 4 years ago committed by GitHub
parent 9d67240cab
commit e7bab13e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      README.md

@ -8,19 +8,21 @@ use std::thread::spawn;
use tungstenite::server::accept; use tungstenite::server::accept;
/// A WebSocket echo server /// A WebSocket echo server
let server = TcpListener::bind("127.0.0.1:9001").unwrap(); fn main () {
for stream in server.incoming() { let server = TcpListener::bind("127.0.0.1:9001").unwrap();
spawn (move || { for stream in server.incoming() {
let mut websocket = accept(stream.unwrap()).unwrap(); spawn (move || {
loop { let mut websocket = accept(stream.unwrap()).unwrap();
let msg = websocket.read_message().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() { // We do not want to send back ping/pong messages.
websocket.write_message(msg).unwrap(); if msg.is_binary() || msg.is_text() {
websocket.write_message(msg).unwrap();
}
} }
} });
}); }
} }
``` ```

Loading…
Cancel
Save