I would like to use thrift with a Java server sending data to a browser using websockets. Is this possible?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With