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

Get a Random Unused TCP/IP or UDP Port #123

Closed
xcthulhu opened this issue May 18, 2017 · 4 comments
Closed

Get a Random Unused TCP/IP or UDP Port #123

xcthulhu opened this issue May 18, 2017 · 4 comments
Labels

Comments

@xcthulhu
Copy link

No description provided.

@AndyGauge
Copy link
Collaborator

I'll give it a stab. Do you think std::net::TcpListener would suffice or should this be Tokio?

@dtolnay
Copy link
Member

dtolnay commented May 19, 2017

I would stick with the standard library if possible. Though I have no idea how to implement this 😅 my first step would be rummaging through docs.

@fox0
Copy link

fox0 commented Jun 29, 2020

let socket = UdpSocket::bind("127.0.0.1:0").unwrap();

@xenowits
Copy link

use std::net::TcpListener;

let listener = TcpListener::bind("127.0.0.1:0").unwrap();

Binding with a port number of 0 will request that the OS assigns a port to this listener. The port allocated can be queried via the TcpListener::local_addr method.

facebook-github-bot pushed a commit to facebook/buck2 that referenced this issue Jul 27, 2022
Summary:
Pass tcp port using `--tcp-port` param from buck2 to buck1's installer binary instead of hardcoding it.

Port is generated using `Binding with a port number of 0 will request that the OS assigns a port to this listener.` : rust-lang-nursery/rust-cookbook#123 (comment)

Reviewed By: krallin

Differential Revision: D38063436

fbshipit-source-id: f74e1fa076ac49b4c0faa1d5141a70594d059541
facebook-github-bot pushed a commit to facebook/buck that referenced this issue Jul 27, 2022
Summary:
Pass tcp port using `--tcp-port` param from buck2 to buck1's installer binary instead of hardcoding it.

Port is generated using `Binding with a port number of 0 will request that the OS assigns a port to this listener.` : rust-lang-nursery/rust-cookbook#123 (comment)

Reviewed By: krallin

fbshipit-source-id: f74e1fa076ac49b4c0faa1d5141a70594d059541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants