AmitKumarDas / fun-with-programming

ABC - Always Be Coding
2 stars 2 forks source link

[go] websocket #39

Closed AmitKumarDas closed 2 years ago

AmitKumarDas commented 3 years ago
// - https://github.com/kairen/websocket-exec/
// Communication protocol
// With all the information in place, the WebSocket should
// be able to establish a connection and the API will start
// communicating. When you write to the WebSocket, the data
// will be passed to standard input (stdin) and on the 
// receiving end of the WebSocket will be standard output 
// (stdout) and error (stderr). The API defines a simple 
// protocol to multiplex stdout and stderr over a single 
// connection. Every message passed through the web socket 
// is prefixed by a single byte that defines which stream 
// the message belongs to.
//
// 0 == stdin  
// 1 == stdout
// 2 == stderr
//
// So for every message received over the socket, you need 
// to get the first byte and decide whether it is stdout or
// stderr. To send data to the API, you need to convert to 
// bytes and prepend 0 to indicate the message belongs in 
// the stdin stream
//
// Connection lifecycle
// One last problem is that there may be proxies and other 
// “roadblocks” on the way to the API, or you may simply 
// reach the TCP timeout. To get around that, send an empty
// message every once in a while to keep the connection busy.
//
// ASCII encoding
// \n is the Newline character 0x0A (decimal 10)
// \r is the Carriage Return character 0x0D (decimal 13)
// the correct sequence is CR-LF