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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the OS pick a random port for us #1

Merged
merged 1 commit into from Aug 24, 2019
Merged

Let the OS pick a random port for us #1

merged 1 commit into from Aug 24, 2019

Conversation

faern
Copy link
Contributor

@faern faern commented Aug 12, 2019

Hello! 馃憢 I ran into this repo while looking around for hole punching stuff. I found a possible improvement. I don't know if this has been considered and rejected for some reason already or not. But I thought I would submit it and see if you like it.

By binding to port zero the OS will pick a random free port
to bind to for us. This has multiple advantages over picking a random
port ourselves:

  1. We don't need to include a random number generator in our program.
  2. We don't risk picking an already used port and fail the bind
    operation. The OS will make sure we get one that is free.

By binding to port zero the OS will pick a random free port
to bind to for us. This has multiple advantages over picking a random
port ourselves:

1. We don't need to include a random number generator in our program.
2. We don't risk picking an already used port and fail the bind
   operation. The OS will make sure we get one that is free.
@dsluijk
Copy link
Owner

dsluijk commented Aug 24, 2019

Hi Linus,

Thank you for your contribution. I will merge the changes.

Please note that this project is not actively maintained, and was build as a Proof of Work for a different application.

Thanks!

@dsluijk dsluijk merged commit 486b52b into dsluijk:master Aug 24, 2019
@faern
Copy link
Contributor Author

faern commented Aug 28, 2019

Thanks! I'm aware it's more of an example. But examples teach people things. And I wanted future developers who land on this code to see that this is possible to do, and better than selecting a port in userland :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants