vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7.14k stars 278 forks source link

Invalid socket address when using udp with host name #265

Open DCsunset opened 1 month ago

DCsunset commented 1 month ago

When using udp: with a host name, it throws an error:

$ websocat -E -b ws-listen:0.0.0.0:8080 udp:example.com:8080
websocat: invalid socket address syntax

However, tcp works as expected:


$ websocat -E -b ws-listen:0.0.0.0:8080 tcp:example.com:8080
vi commented 1 month ago

There is a special support for TCP with hostnames (it supports trying multiple resolved addresses and choosing the one that works). This support appeared relatively late in Websocat history.

What shall udp:example.com do if it resolves to e.g. 1.2.3.4 and [5678::9]?

DCsunset commented 1 month ago

That's a good point. I think one approach is to use a random address (usually both should work). Another approach is to add udp4 and udp6 as socat does.

vi commented 1 month ago

What if multiple addresses from the same family is returned?

Shall the address be resolved once or periodically refreshed?

DCsunset commented 1 month ago

For the first question, I think using the first one should be good for most cases and is easy to implement. (If any address doesn't work, it should be the responsibility of the server instead of this app)

For the second question, I think either approach is good enough for most apps to work.