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

sending packets to anything else than a local adress doesn't work #301

Open
TanTanDev opened this issue Sep 21, 2021 · 4 comments
Open

sending packets to anything else than a local adress doesn't work #301

TanTanDev opened this issue Sep 21, 2021 · 4 comments

Comments

@TanTanDev
Copy link

I was scratching my head because my client and server worked just fine locally.
It also worked just fine on my vps to run both client and server at the same time.

But as I was trying to connect my computer to my vps(client to server), no connection was ever established.

So I downloaded wireshark to investigate and what I found was that only packets going to a local address, (starting with 127)
Was ever sent.

As a test I was sending a packet to localhost, and then the address of google.com.

    let adress = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12345);
    let result = packet_sender.send(laminar::Packet::reliable_unordered(adress, [1,1].into()));
    println!(" trying to send to address {} result : {:?}", adress, result);

    // I've verified pinging this address from command line works
    let google_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(216, 58, 211, 14)), 22);
    let result = packet_sender.send(laminar::Packet::reliable_unordered(google_address, [1,1].into()));
    println!(" trying to send to address {} result : {:?}", google_address, result);

the println!() both print Ok(())

The only outgoing packets appearing in wireshark filtering with udp, is the packet sent to localhost.

I'm using laminar 0.5

@nic96
Copy link

nic96 commented Sep 22, 2021

What IP address are you binding the server on? You should probably bind it on 0.0.0.0 to listen on any IP. With the client you can just use the bind_any() method. After that you should be able to send a packet from the client to the server using the servers public IP and port. Once the server receives the packet it can respond to the client on the packet.addr() that it received.

@nic96
Copy link

nic96 commented Sep 23, 2021

Disregard my previous comment, I actually ran into the same issue and the solution was to instead of using bind_any() on the client to bind on 0.0.0.0:0. With bind any it was just listening on 127.0.0.1.

@bschwind
Copy link

I just ran into the same issue, I was binding the client on 127.0.0.1:0 instead of 0.0.0.0:0.

Changing that makes it work as expected.

@PerfectlyFineCode
Copy link

PerfectlyFineCode commented Jul 1, 2023

Thank you!

This was also my issue, and they don't explain this in the method of bind_any() docs is really weird. Fairly sure they also recommended the use of bind_any(), which is strange.

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

4 participants