Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does "connect" not support ipv6? #341

Open
kkoang opened this issue Jan 19, 2023 · 0 comments
Open

Does "connect" not support ipv6? #341

kkoang opened this issue Jan 19, 2023 · 0 comments

Comments

@kkoang
Copy link

kkoang commented Jan 19, 2023

// service
use ws::listen;
fn main() {
    // error code
    if let Err(err) = listen("[::]:3012", |out| {
        // correct code
        // if let Err(err) = listen("0.0.0.0:3012", |out| {
        move |msg| {
            println!("server receive: '{}'.", msg);
            let new_msg = format!("you:{}!!", msg);
            println!("server return message '{}'.", new_msg);
            out.send(new_msg)
        }
    }) {
        println!("Fail create WebSocket connection due to error: {:?}", err)
    }
    println!("service over")
}
// client
use ws::{connect, CloseCode};
fn main() {
    // error code
    if let Err(err) = connect("ws://[::1]:3012", |out| {
        // correct code
        // if let Err(err) = connect("ws://127.0.0.1:3012", |out| {
        if out.send("Hello").is_err() {
            println!("Failed");
        } else {
            println!("Client send Hello")
        }
        move |msg| {
            println!("Client receive: '{}'.", msg);
            out.close(CloseCode::Normal)
        }
    }) {
        println!("Fail create WebSocket connection due to error: {:?}", err);
    }
    println!("client over");
}

Run error when url is "ws://[::1]:3012".
Run correctly when url is "ws://127.0.0.1:3012".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant