Open cawthm opened 5 years ago
Technically WS is a socket connection but the underlying TCP channel is not exposed. WS is using higher level protocol which basically send data in batches (frames), either binary or string frames. So what you see is on the R side is exactly those frames which you should decode with one of those packages that you have listed.
Thank you for the reply.
Technically WS is a socket connection
I assume you mean 'connection' here in the everyday sense of an internet endpoint. Or by contrast, do you mean the WS is creating something a la base::socketConnection()
?
In R, there seems to be a class of objects described nicely in the answer to this SO post, called connections. Eg, see class(file())
or class(pipe("foo"))
or the docs at ?file
. It is such a connection object that is anticipated by the packages I mention.
Anyway, I may be missing something basic, but back to my original point: It might be nice to see an example or vignette comparing/ contrasting/ converting the WS stream with/to a connection object.
I assume you mean 'connection' here in the everyday sense of an internet endpoint.
I mean in the common sense of TCP connection which both HTTP and WS protocols use under the hood. R's socketConnection opens a TCP connection.
WS is using websocketcpp under the hood and is not relying on the base::socketConnection
. Both of these are socket connections, but the former (my guess, I am just an accidental lurker) you cannot directly access from R. I would personally be interested in completely dropping WS frame wrapper and getting the bare-bones TCP connection but I would be surprised if this is possible.
The R abstraction is very basic, the server side is capable to accept only one connection.
Examples of consuming XML/JSON/etc. in the documentation somewhere would be great.
websocket
is not a good way to interact with a server at the TCP level and never will be, because it's very specifically a WebSocket client library 😄
That said, I recognize this distinction is not obvious to many, and so any addition to the documentation that provided further context or contrasted websocket
use cases with socketConnection()
would be more than welcome.
because it's very specifically a WebSocket client library smile
FWIW, netty allows dropping the WS framing machinery after the handshake, thus leaving you with bare-bones TCP.
Dropping into TCP is definitely a cool feature. If anyone thinks there's a good case for adding it, then we're open to considering a strategy/PR. On its own though, feature-parity with netty is a non-goal. Netty has a much broader scope than websocket
.
I also don't know if WebSocket++ supports it, which would be required for websocket
to.
When one opens a websocket to receive a stream of data, it is usu either in JSON, XML, or maybe binary form. There are good, established packages (jsonlite, xml2, DBI, etc) for dealing with R connections that stream such data in or out. It would nice to have an example of websockets interfacing with one of these in a natural and seamless way. My understanding is that a ws object is not a connection per se, and understanding that difference would be hugely helpful.