vi / websocat

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

WebSocket ping pattern #80

Open Foster024 opened 4 years ago

Foster024 commented 4 years ago

Hey. A typical request for a ping command looks like this template: Ping Pong But there are servers (like this wss: //pubsub-edge.twitch.tv) that do not understand this syntax. They understand this: {"type": "PING"} {"type": "PONG"}

The "--ping-interval" flag sends ping by the first pattern. Because of this, after about 5 minutes, the connection is disconnected. How to make it send ping on the second pattern?

vi commented 4 years ago

Do you mean WebSocket-level pings or some application-level (e.g. IRC over WebSocket) pings?

If it is application-level (i.e. text or binary WebSocket messages with semantic of ping instead of a special WebSocket message type used for pings) then you need to implement such pings yourself by periodically writing something into Websocat for it to keep the connection alive.

Foster024 commented 4 years ago

I mean the https protocol application level pings on top of WebSocket. Yes, I made a “crutch” which I run in the terminal: ./ping.sh

while [0] do echo -e "{" type ":" PING "} \\ n" | nc 127.0.0.1 1234 sleep 300 done c

vi commented 4 years ago

Yes, something like this should be used. I don't think handling of application-level pings should be part of Websocat itself.

Foster024 commented 4 years ago

I want to ask you. Is it possible to transfer the contents of a file from a local drive? This is necessary so as not to manually enter the initial commands from the keyboard each time after establishing a connection to the server. A prerequisite should be the ability to continue the created communication sss wss. I tried to do it like this: cat commands.txt | websocat wss: //site.com/ But after executing the commands from the commands.txt file, the websocat shell closes and I again see the bash terminal.

vi commented 4 years ago

Maybe you want rlwrap websocat wss://site.com/?

You can then use line editing and input history.

Foster024 commented 4 years ago

it is amazing! :) ty!