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

RaknetListener#accept() freezes for ever and don't accept any new connections. #13

Open
EvilCodeZ opened this issue Mar 28, 2023 · 0 comments

Comments

@EvilCodeZ
Copy link

I've made normal client server application that uses rust-raknet, but once the first client is accepted by the RaknetListener, the listener stop accepting new connections.

So I made a test program that binds a RaknetListener and accepts clients in a loop and reads data from them and prints it. And i've added loop that connects clients to the listener. This test program also stop accepting new connections after few clients that got accepted. Code below:

let mut server = rust_raknet::RaknetListener::bind(&"0.0.0.0:1337".parse().unwrap()).await.unwrap();
    server.listen().await;
    log::info!("Listening on {}", server.local_addr().unwrap());
    
    tokio::spawn(async move {
        loop {
            log::info!("Accepting...");
            let client = server.accept().await.unwrap();
            log::info!("Accepted: {}", client.peer_addr().unwrap());
            tokio::spawn(async move {
                loop {
                    let msg = client.recv().await;
                    log::info!("Received: {:?}", msg);
                    if msg.is_err() {
                        break; // Stop the task
                    }
                }
            });
        }
    });

    tokio::time::sleep(std::time::Duration::from_secs(2)).await; // Wait some time for the server to start accepting connections

    loop {
        tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        tokio::spawn(async move {
            log::info!("Connecting new client...");
            let client = rust_raknet::RaknetSocket::connect(&"127.0.0.1:1337".parse().unwrap()).await.unwrap();
            log::info!("Connected to {}", client.peer_addr().unwrap());
            client.send(&[0xFE, 0x02, 0x03, 0x04], rust_raknet::Reliability::ReliableOrdered).await.unwrap();
            let _ = client.close().await;
        });
    }
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