Closed clarkewd closed 4 years ago
The syntax is autoreconnect:ws://echo.websocket.org
Note that in current version of websocat there is no delay or ratelimit of reconnect attempts, which may lead to flood / CPU busy spin.
What do you want to attain? Maybe there is another way to do it? Do you use websocat interactively or as part of some script?
Thank you for the fast reply!
I've downloaded the precompiled binary and on Windows 10 here is what I get:
c:\> websocat_win32.exe autoreconnect:ws://echo.websocket.org
Specify ws:// or wss:// URI to connect to a websocket
websocat: Invalid command-line parameters
I'd like to use it to send updates to another program, I'd just like it to recovery automatically if there were a wifi disconnect / reconnect. I'm open to any suggestions on that.
Try websocat -t - autoreconnect:ws://echo.websocket.org
.
autoreconnect:
and other overlays are for non-simplified two-argument version invocation of Websocat.
worked perfectly - thank you!
Hi Vitaly,
I haven't used rust
previously and I'm sure there are probably other things to consider, but would it be difficult to add a delay to the reconnect loop?
Would this work?
thread::sleep(::std::time::Duration::from_millis(500));
If it were added here?:
Even a short delay seems like it would prevent the flood / CPU busy spin.
I considered adding a delay almost from the very beginning, but at that moment Websocat contained no timers whatsoever, so I postponed it.
thread::sleep
Bad idea, as Websocat is single-threaded and polling and stopping entire thread should be avoided.
Implemented proper timeout, also created a set of pre-compiled executables.
This is so great! Do you accept donations?
Is there any update of the syntax?
➜ /tmp websocat autoreconnect:ws://echo.websocket.org
Specify ws:// or wss:// URI to connect to a websocket
websocat: Invalid command-line parameters
No update on syntax. But samples above weren't right in the first place. You need to use longer, two-argument form of Websocat invocation in order to use advanced features:
websocat -t - autoreconnect:ws://echo.websocket.org
Currently one-positional-argument form of Websocal command line is reserved only for trivial clients and servers without any overlays. The error message may indeed be improved.
You may also want to adjust --autoreconnect-delay-millis
.
@vi Can websocat handle intermittent disconnects without breaking overlayed TCP connections when websocket is used as a proxy? I've checked reuse-raw
but it says it's "unreliable".
I've checked reuse-raw but it says it's "unreliable".
"Unreliable" probably means that with multiple simultaneous clients reuse-raw
would send data to some single, undetermined one. Also when TCP client abruptly disconnects, some (maybe unpredictable amount) data designated for it can be lost and not be seen by the next client (i.e. there are no acknowledgements and resends).
On the other hand, unlike reuse-broadcast:
, it should not deliberately drop data to slow or missing clients - backpressure will apply.
With --conncap 1
one of the issues may be irrelevant.
... intermittent disconnects without breaking overlayed TCP connections ...
Do you need a reuser in the first place for this? Maybe just plain autoreconnect:
would suit? I don't remember whether it would resend a message that triggered the reconnection (i.e. made Websocat realise that the WebSocket is not longer connected).
@vi autoreconnect:
corrupts SSH connection after websocket reconnects. Every other option I tried made SSH client aware of disconnect.
Some data loss (hence encrypted connection corruption) is hard to avoid in this scheme. Holding a persistent and reliable connection over abruptly terminating and reconnecting WebSocket connections requires some overarching, persistent sequence numbers and retransmits (i.e. additional parts both at client and server).
Maybe you can set up Wireguard VPN over websocat (and then use SSH over that Wireguard connection)? Wireguard handles unreliable connections nicely and will provide slower, but more reliable link to users. If needed, Wireguard protocol can be used completely in userspace (using e.g. wgslirpy or onetun).
@vi Would Wireguard actually help with this? I'm assuming my issue is not just mild packet loss along the way but some reverse proxy that abruptly closes websocket TCP connection.
I'm really cautious about adding more layers since that would be, like what, TCP (SSH) in UDP (WG) over TCP (WS)?
abruptly closes websocket TCP connection
Dropped unacknowledged data when this happens would be interpreted as a packet loss by upper TCP layer.
... cautious ...TCP (SSH) in UDP (WG) over TCP (WS)?
Yes, it is TCP over TCP, which is problematic. The same layer that helps recover the data on reconnections would also cause slowdowns and overhead.
Maybe this specific task (good reliable stream socket over series of unreliable stream sockets) needs to be solved separately, with a dedicated tool. Maybe I'll roll such tool someday.
On Windows 10, I can run this command with no problems:
Is it possible to use the
autoreconnect
option as well? I haven't been able to figure out the syntax for this. I've tried these without any luck:Thank you for creating and sharing wonderful utility.