websocat
websocat copied to clipboard
Raw mode stdio?
I have a simple WS echo server which just repeats text or binary frames with a trivial modification. If I connect to it with websocat
with default options from a terminal, after typing a line of text and pressing Enter I get that line back, as expected. However I wanted to try getting character-by-character responses and passed --no-line
(also -b
), to no effect: it still does nothing until Enter is passed, then sends a frame containing the entire line. Am I misunderstanding what this option does?
The line is buffered until you press Enter not in Websocat, but in Linux (or whatever) kernel.
You may want to set terminal options with stty
prior to starting websocat client. Currently Websocat (unlike Socat) does not support controlling PTYs or setting terminal options; this may be implemented in future version.
Baseline:
$ websocat -b ws://echo.websocket.org/
asdf
asdf
234324
234324
Script:
#!/bin/bash
stty raw
trap 'stty cooked' EXIT
websocat "$@"
Run:
$ /tmp/websocatterm.sh -b ws://echo.websocket.org/
aaBBCCdd11223344^C^C
You may want to set detailed stty options, not just raw
.
That works indeed! Feel free to close, unless you would like this to be mentioned in docs.
Man, this tripped me up hard while trying to connect to the MicroPython console (WebREPL).
~~FWIW the raw setting doesn't work for me at all on macOS and neither do any of its sub-settings. Either nothing changes or (apparently) nothing happens at all. Never do I get the desired effect of directly sending the characters as I type.~~
Edit: This seems to be a (somewhat?) MicroPython specific issue.
It would be super nice if a "just works" mode for this was introduced. The use case seems common enough.