When one IP address fails

I wrote my own gopher server several years ago. And it works fine for my own uses, But I could not load gopher://raymii.org/ [1]. I could use telnet (the gopher protocol is very easy to use by hand). I could use nc. But my client could not connect.

I finally dived into the problem and I found the issue—not all the addresses for raymii.org work! My code would call getaddrinfo(), which returns a list of addresses, and my code would just use the first one returned. Only in the case for raymii.org not all the addresses accept connections. And that's an issue that I've never encountered before.

The fix was easy—attempt to connect to each address and return when the first one connects.

[1] gopher://raymii.org:70/1

Gemini Mention this post

Contact the author