vi / websocat

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

How to send between virtual comm port and websocket? #144

Closed dresco closed 2 years ago

dresco commented 2 years ago

Apologies, I've not been able to figure this out by myself, but am assuming it should work with the right combination of socat and websocat?

My use case is a server that accepts websocket & serial connections, and some legacy client software that only supports serial port connections (that I would like to run remotely).

I can successfully communicate with the server from the command line, using something like websocat --text ws://192.168.100.40:80, but I can't figure out how to get data to & from a virtual serial port so that I can use the client software. I've tried this sort of thing socat pty,raw,link=/dev/ttyS99 exec:'websocat --text ws\://192.168.100.40\:80 -', but no joy..

Thanks in advance!

vi commented 2 years ago

Have you tried pointing Websocat at tty directly?

websocat --text open-async:/dev/ttyS99 ws://192.168.100.40:80

That won't open pty or set raw mode though. The latter can be done with explicit stty.

Combination with socat should work, provided you got all the escaping correct. What fails in that mode? Node that websocat --text works line by line. You may want --binary if you want individual bytes to be transferred.

dresco commented 2 years ago

Thanks, I think I'm getting there..

As a (text based) PoC, the following setup seems to work;

socat PTY,link=./virtual-tty1,echo=0 PTY,link=./virtual-tty2,echo=0
websocat --text open-async:virtual-tty1 ws://ws.vi-server.org/mirror:80
screen ./virtual-tty2

socat creates and ties together 2 virtual serial ports, websocat is attached to one, and screen (representing the client software) attaches to the other. I can then see my input being echoed from the server..

vi commented 2 years ago

websocat --text open-async:virtual-tty1 ws://ws.vi-server.org/mirror:80

--text may mangle binary data. For tty bytes I'd recommended --binary.


If shell server at ws://192.168.100.40:80 manages PTY itself then I don't think you need another second PTY on the client site, just the raw mode of existing terminal. here are example commands to tunnel shell over a pair of Websocats.

dresco commented 2 years ago

Many thanks, has got me up & running.

Am still thinking I need both virtual ports on the client machine? With a USB serial connection, I would get a CDC ACM port for the client software, which I don't have in this case.

Anyway, this is what I ended up with;

socat PTY,link=./virtual-tty1,raw,echo=0,unlink-close=0 PTY,link=./virtual-tty2,raw,echo=0,unlink-close=0
websocat --binary open-async:virtual-tty2 ws://192.168.100.40:80

The client can then use virtual-tty1, and seems to be working well..