laminar
laminar copied to clipboard
sending packets to anything else than a local adress doesn't work
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
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.
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
.
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.
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.