Compilation errors on tungstenite home page example

Compilation errors using simple example https://github.com/snapview/tungstenite-rs
What's the issue? It looks like a legitimate error to me.

use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::server::accept;

/// A WebSocket echo server
fn main () {
    let server = TcpListener::bind("127.0.0.1:9001").unwrap();
    for stream in server.incoming() {
        spawn (move || {
            let mut 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(msg).unwrap();
                }
            }
        });
    }
}
error[E0603]: module `server` is private
  --> src/main.rs:3:18
   |
3  | use tungstenite::server::accept;
   |                  ^^^^^^ private module
   |
note: the module `server` is defined here
  --> /home/jpm/.cargo/registry/src/github.com-1ecc6299db9ec823/tungstenite-0.15.0/src/lib.rs:22:1
   |
22 | mod server;
   | ^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0603`.
error: could not compile `goo`

To learn more, run the command again with --verbose.
[dependencies]
tungstenite = "0.15.0"
$  rustc --version
rustc 1.51.0 (2fd73fabe 2021-03-23)

I'm guessing the example is from an older version of Tungstenite.

The server module was made private by this PR:

https://github.com/snapview/tungstenite-rs/pull/226

You might want to open an issue on that repo asking them to update the example in the README.

Thanks. I opened an issue.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.