-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
tcpserver documentation instructions can cause confusion. #4728
Comments
This helps with problems mentioned in issue 5728 crystal-lang#4728
This is a mere example. You can't expect your resolver to behave the sale in scenarios where you specify ipv4 specifically, but don't specify it otherwise. What happens if you remove IMHO the example is just fine. |
I don't know if the curl is as much of a problem. I just tried this and the browsers on macOS do not work. That seems like a problem. |
After more research I think this does not work in the browser because you need to add the protocol and content-length.
|
This is an example of a simple TCPServer without any application protocol. So it will certainly not work with an HTTP protocol, neither with curl nor a browser, because it returns an invalid HTTP response. (actually, curl doesn't complain and just prints the received contents without interpreting it as an HTTP response) This tcp server can be tested for example with netcat: |
I was not considering that when I ran across this. I think this issue might be able to be closed. I am not sure since @rdp has not responded. |
I believe the problem I ran into was "first up your crystal server, using the example, add some HTTP header responses, now in a console, since it's localhost, try to do $ curl http://127.0.0.1:port" |
I'd think binding to "localhost" would bind to both the ipv4 and ipv6 versions of localhost (ruby seems to have this behavior, but oddly OS X but not linux, weird). Crystal's In linux crystal's netcat on OS X (from homebrew) with crystal server example gives Cheers! |
But it would probably be helpful to replace |
Yeah 127.0.0.1 would clear things up. I think preferably if you bind to "localhost" it should either bind to "ipv4 over ipv6" (if both are available) or bind to both, to increase compatibility with older programs (like some old versions of netcat). The host-less option Is that worth filing a separate issue for "ipv4 default instead of ipv6", thoughts? |
Just want to note that this affects Linux as well (Ubuntu). netstat shows: Apparently, ipv6 is the default for "localhost" so Crystal is not wrong here. Let's just add a note to the docs and close this issue. |
"localhost" defaults to ipv6. resolve crystal-lang#4728
Binding If you want to bind all addresses, there's
This is not the case for all platforms. MSDN docs for
Because of this, I think this solution would be bad. I think the best option would be to either use the host-less option |
Hello.
The docs for https://crystal-lang.org/api/0.23.0/TCPServer.html have this example:
In OS X if I run this, and fire up my "client of choice" and attempt to connect to localhost:1234 using ipv4, I get an unexpected "connection refused", here's how to repro:
It appears that it's binding to the ipv6 version of localhost, and not the ipv4 version, by default, which is what causes my confusion. The ideal would be to bind to both. If that's tricky, then perhaps change the example to this:
server = TCPServer.new("127.0.0.1", 1234)
just so that people like me, who see localhost and think "127.0.0.1" don't get confused by the example.
Thanks!
The text was updated successfully, but these errors were encountered: