Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does thrift support sending data over websockets?

I would like to use thrift with a Java server sending data to a browser using websockets. Is this possible?

like image 344
Xavier Avatar asked Sep 28 '11 12:09

Xavier


3 Answers

In thrift there are 2 important things: protocol, and transport. Protocol defines how is data serialized into the data stream. And transport defines how are those streams of data exchanged between communicating entites.

There is json protocol in thrift which is supported by javascript, but as far as transports go I think Thrift supports only 2 transports raw tcp, and http. Later can be used to invoke operation on a HTTP server, and fetch the result from it, but not the other way around as you need it.

I guess you might be able to use json protocol, but you would need to roll your sleeves up and implement your own websockets transport. This could be a a non trivial task.

like image 182
Davorin Ruševljan Avatar answered Nov 11 '22 06:11

Davorin Ruševljan


According to this issue: https://issues.apache.org/jira/browse/THRIFT-2355 Thrift recieved support for web sockets in the javascript compiler for version 0.9.2.

like image 29
Josh Wittner Avatar answered Nov 11 '22 05:11

Josh Wittner


As of v.0.9.0 of Thrift, the answer is no.

On the client side, the javascript generated uses AJAX for it's transport as seen in Thirft.js library, so if a client was to use a WebSocket, then transport in Thrift needs modified.

On the server side, the Java code shows a socket server, but I believe it doesn't have the handshaking needed for the WebSocket server side code. Again, probably be added somewhat easily. It probably makes more sense for you to use jWebSocket as your server and the Java object classes created by thrift than the Thrift version of the server. You can inspect the code to know it better in Thrift. see /lib/java/src/org/apache/thrift/ section of the trunk in Thrift.

like image 34
Rich Elswick Avatar answered Nov 11 '22 06:11

Rich Elswick