Retrieving socket after binding to port 0 #1577
Unanswered
michalwarda
asked this question in
Q&A
Replies: 2 comments 6 replies
-
Ssl is 0 or 1 |
Beta Was this translation helpful? Give feedback.
6 replies
-
In case that helps anyone: inline constexpr bool wSSL = false;
app.listen(
port, [&ctx, port](us_listen_socket_t* socket) -> void {
if (socket) {
int actual_port = us_socket_local_port(wSSL? 1: 0, (us_socket_t*)socket);
assert((!port && actual_port) || (port == actual_port));
fmt::print(ctx.out(), "Serving over HTTP{} on port {}\n", wSSL? "S": "", actual_port);
}
}
); Which results in:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to create a server with port 0 as the parameter to get a dynamically assigned port. The problem though is that I'm not sure how to retrieve the port then. Any suggestions?
And if it's important I'm using
capi
.Beta Was this translation helpful? Give feedback.
All reactions