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

Use ::bind_any() instead of ::bind(addr) in example for client to avoid confusion #306

Open
DragonAxe opened this issue Feb 6, 2023 · 1 comment

Comments

@DragonAxe
Copy link

In the server_client.rs example, there are two address:port constants, one for the server and one for the client:

const SERVER: &str = "127.0.0.1:12351";

let addr = "127.0.0.1:12352";

These addresses are 40 lines apart, so I missed that the port numbers are different. Port 12351 for the server and 12352 for client. When adapting the example to my project, I accidentally merged the two addresses to one variable.

I feel it would be better to use ::bind_any() instead of ::bind(addr) for the client to help prevent the confusion I encountered.

let mut socket = Socket::bind(addr)?;

It seems common for client programs to pick any open port to bind to which is why ::bind_any() seems like a good option.

@merlindru
Copy link

I learned about bind_any through your post. Thank you!

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