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

Couldn't connect to server with unwrap() called on Result on a Err value #2

Closed
feelingnothing opened this issue Apr 20, 2022 · 10 comments

Comments

@feelingnothing
Copy link

feelingnothing commented Apr 20, 2022

Created simple packet listener, my code:

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();
    let mut socket = rust_raknet::RaknetListener::bind("0.0.0.0:19132".parse().unwrap()).await.unwrap();
    socket.listen().await;

    while let Ok(mut s) = socket.accept().await {
        tracing::info!("Accepted connection from {:?}", s.local_addr());

        let mut connection = rust_raknet::RaknetSocket::connect(&"51.210.143.233:19132".parse().unwrap()).await.unwrap();
        loop {
            if let Ok(buf) = s.recv().await {
                tracing::info!("FROM CLIENT: {:?}", &buf);
                connection.send(buf.as_slice(), Reliability::Reliable).await;
            }

            if let Ok(buf) = connection.recv().await {
                tracing::info!("FROM SERVER: {:?}", &buf);
                s.send(buf.as_slice(), Reliability::Reliable).await;
            }
        }
    }
}

Error:

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReadPacketBufferError', C:\Users\dolabaeb\.cargo\registry\src\github.com-1ecc6299db9ec823\rust-raknet-0.3.1\src\socket.rs:357:137

On line https://github.com/b23r0/rust-raknet/blob/main/src/socket.rs#L371

@b23r0
Copy link
Owner

b23r0 commented Apr 21, 2022

Please provide more client-side related information, such as the client-side code that triggered the issue

@b23r0
Copy link
Owner

b23r0 commented Apr 21, 2022

i guess you want to write a minecraft proxy,could you tell me your minecraft client version?

@feelingnothing
Copy link
Author

Last PC release, so i guess 1.18

@b23r0
Copy link
Owner

b23r0 commented Apr 21, 2022

I already have hands-on experience developing Minecraft bedrock server reverse proxies through rust-raknet, but I don't have this problem with you. I suggest you try the following ways to solve the problem.

  1. Use the latest rust-raknet version 0.5.0.
  2. Do not use Reliability: : Reliable, but the use of Reliability: : ReliableOrdered.
  3. Use tokio select! to handle packet swapping.

Here is a piece of code I used to test the reverse proxy for your reference.

async fn proxy(){
    let mut listener = RaknetListener::bind("0.0.0.0:19199".parse().unwrap()).await.unwrap();
    listener.listen().await;
    loop{
        let mut client1 = listener.accept().await.unwrap();
        let mut client2 = RaknetSocket::connect(&"192.168.0.12:19132".parse().unwrap()).await.unwrap();
        tokio::spawn(async move {
            println!("build connection");
            loop{
                tokio::select!{
                    a = client1.recv() => {
                        let a = match a{
                            Ok(p) => p,
                            Err(_) => {
                                client2.close().await.unwrap();
                                break;
                            },
                        };
                        match client2.send(&a, Reliability::ReliableOrdered).await{
                            Ok(p) => p,
                            Err(_) => {
                                client1.close().await.unwrap();
                                break;
                            },
                        };
                    },
                    b = client2.recv() => {
                        let b = match b{
                            Ok(p) => p,
                            Err(_) => {
                                client1.close().await.unwrap();
                                break;
                            },
                        };
                        match client1.send(&b, Reliability::ReliableOrdered).await{
                            Ok(p) => p,
                            Err(_) => {
                                client2.close().await.unwrap();
                                break;
                            },
                        };
                    }
                }
            }
            client1.close().await.unwrap();
            client2.close().await.unwrap();
            println!("close connection");
        });
    }
}

I will also be testing the issues triggered by your code soon, in about a week.

@feelingnothing
Copy link
Author

@b23r0 I tested code you provided, I see why my example didn't work, I basically blocked it with await point. But the code you provided did not seem to work, testing with MiNET server doesn't get any packets from client. and proxy doesn't receive any from client, just pointing at sky maybe it is skipping the first McPELogin packet?

@feelingnothing
Copy link
Author

UPDATE: I got packet, don't know what because I was just logging a packet being received, but it does not work all the times, in 15-20 tries I didn't get any, don't know whats the problem

@b23r0
Copy link
Owner

b23r0 commented Apr 21, 2022

UPDATE: I got packet, don't know what because I was just logging a packet being received, but it does not work all the times, in 15-20 tries I didn't get any, don't know whats the problem

Your test results are very different from mine. Can you provide more test information, including minecraft server version, rust-raknet version used, the operating system information of the client, and the environment configuration of the proxy you built.

I've served large users through the mc proxy written by rust-raknet and im sure it works.

You can contact to my discord we can continue to discuss your specific issues.

@b23r0 b23r0 reopened this Apr 21, 2022
@b23r0
Copy link
Owner

b23r0 commented Apr 22, 2022

UPDATE: I use 1.18.12 Minecraft client connect to MiNET server but raise a error.

1650633917(1)

MiNET does not support Minecraft client version 1.18.x.

I proxied MiNET through rust-raknet and it produced the same error. I think the problem you mentioned may be caused by MiNET, if you don't have another reply, I will close this issue.

@b23r0
Copy link
Owner

b23r0 commented Apr 22, 2022

I've added an example that I use for reverse proxy testing. Hope it helps you.

https://github.com/b23r0/rust-raknet/tree/main/example/proxy

@b23r0 b23r0 closed this as completed Apr 22, 2022
@b23r0
Copy link
Owner

b23r0 commented Apr 23, 2022

I just compiled the latest version of MiNET and can connect successfully with the proxy example I gave.

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

2 participants