HaxeFoundation / HaxeFoundation/haxe
[sys] Make "any address" setting for sys.net.Socket.bind more prominent
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Currently, `bind(host, port)` method in `sys.net.Socket` requires both values to be set (passing `null` for `host` will cause an exception).
Requiring to supply the address to bind the server socket to is not common in "high-level" APIs and most people may not know what to pass in there.
At the same time, `sys.net.Socket` does not expose any of the default "low-level" constants from inet.h, and, most importantly, does not have a single hint of `INADDR_ANY`, which is commonly used if the API function does not have a "hostname" parameter.
Presence of `Host.localhost` does not make the situation better either - while it is most commonly used in code examples, it may return various addresses, which may not necessarily be reachable from "outside".
Of course, if you've thoroughly read the manual entry for the low-level bind(), you may know that `INADDR_ANY` is a macro for `0`, and thus can be replaced with a hostname [0.0.0.0](https://en.wikipedia.org/wiki/0.0.0.0), but how many of the users do, really?
I'd like to suggest to add a constant to the `Host` class that would be equal to `0.0.0.0` and have a snippet of documentation describing the usage with `Socket.bind`.
Contributor guide
Assessment
This issue has not been assessed yet.