简体   繁体   中英

Apache Thrift Java-Javascript communication

I'm writing a Java server based on Apache Thrift, that will receive data from a Javascript client. I have completed the Java server, but the problem is that I can get a working example for the Javascript client (I was unable to find a good example for it). the examples in the build documentation aren't very helpful. My current Javascript client is below:

function testServer() {
    try {
        var transport = new Thrift.Transport("http://127.0.0.1:9090");
        var protocol  = new Thrift.Protocol(transport);
        var client = new JavaEventClient(protocol);

        var alive = client.isServerAlive();
    } catch(e) {
    }
}

testServer();  

But the code isn't working - as the Java server throws an "Out Of Memory" Error. I don't know if the error is due to my client code or Apache Thrift.

What am I doing wrong?

Looks like problem problem in communications. Maybe you use different protocol or transport on server and client. or bug in implementations of that protocols. // as example I found bug with utf8 characters in thrift-javascript serialization.

Please looks on https://github.com/imysak/using-thrift (My friend and I wrote this simple example of communication Java-Node.js via thrift).

I hope you can use something from our JS implementation.

The Out Of Memory error occurs when your server is using TBinaryProtocol but you try to access it in another way, eg using a browser (which speaks HTTP). IMO that is a bug. There should be some nice error message instead.

The files how to make a Thrift Java server work with an Thrift Javascript client are scattered throughout the source. I puzzled them together here: https://github.com/LukeOwncloud/ThriftJavaJavascriptDemo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM