Comments (5)
@sgraham, thanks for the feedback. cpp-httplib doesn't have a method that tells the actual port.
It seems like we can figure out the actual port with getsockname
system call. But it's a bit difficult to pass the result to a user, since Server::listen
method is a blocking method.
We are able to make a method like Server::get_actuall_port
. But a use can call the method only on a different thread.
Another way is that we could make a method like Server::on_connected
which takes a callback function where we will receive the actual port number.
I'll get back to you when I decide which solution should be taken.
from cpp-httplib.
Thank you for considering this request! Perhaps an on_connected() would be slightly simpler conceptually, but either of those solutions seem fine to me.
from cpp-httplib.
Another thought I just had... I think the port is selected by this point? https://github.com/yhirose/cpp-httplib/blob/master/httplib.h#L1413
Perhaps it would be possible to split optionally split listen()
at that location, so that the user can call something like bind_to_any()
, which could return the selected port, and then call listen_after_bind()
. I'm not sure if that's better or worse than an optional callback though.
from cpp-httplib.
Something like https://github.com/yhirose/cpp-httplib/compare/master...sgraham:system-assigned-port?expand=1 is what I was thinking for above, if you like that approach.
from cpp-httplib.
@sgraham, your approach looks much better than mine! Could you make a pull request, so that I could merge it to my master. The only thing is the name of bind_to_any()
. Could something like bind_to_any_port()
be clearer to users?
from cpp-httplib.
Related Issues (20)
- How to detect client timeouts/disconnects when implementing long polling HOT 1
- SSL Connection Failed HOT 2
- Segmentation Failed on client side only? HOT 2
- Can't disable CORS policy for POST Server handler HOT 1
- does the community weclome a new blood?/(ㄒoㄒ)/~~ HOT 1
- Server process doesn't get killed when window that is running process gets closed HOT 2
- Client timeout HOT 4
- Crash on httplib post method triggered by malloc.c HOT 8
- What about current version of library ? HOT 1
- When making a form-data request using OkHttp, a status code of 400 is returned. HOT 1
- Server::set_payload_max_length cannot increase the payload size beyond 8 KiB HOT 4
- POST with no POST data returns HTTP 400 HOT 13
- post multipart/form-data errror HOT 1
- usage of rand() is not seeded and depends on seeding by parent program HOT 10
- After using split.py and enable CPPHTTPLIB_ZLIB_SUPPORT, I can't use EventSource. HOT 3
- can't communicate within local network HOT 1
- Doesn't work containerized HOT 1
- A serious problem, crash ... because of request default constructor error!!!!!!! HOT 3
- Already calling select() separately HOT 4
- 【BUG】iOS or macOS http file server not support files larger than 3G HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp-httplib.