Background: The company uses node to communicate with services written in other languages (Java).
1, Service end Helloserver.js
var thrift = require (' thrift '); var helloservice = require ('./helloservice '); var server = Thrift.createserver ( HelloService, {hello:function (para, success) {Console.log ("para:" + para); Success (NULL, "Hi, client! I am server! ");}}, {}); Server.listen (8080);
2, Client Helloclient.js
var thrift = require (' thrift '); var helloservice = require ('./helloservice ');//create connection and client var connection = Thrift.createconnection (' localhost ', 8080); Connection.on (' Error ', function (err) { console.error (err);}); Var client = thrift.createclient (helloservice, connection);//Call the Hello method var para = ' hi server! i am client. '; Client.hello (Para, function (err, res) { if (err) { console.error ("error: " + err); }else{ console.log ("result: " + res); } connection.end ();});
3,thrift Compiler version: 0.9.2.
4, this version of node third-party library thrift Server.js file has a bug that causesThe third parameter of Thrift.createserver (processor, handler, options) must be passed.
The code in the red box should be:
if (options && options.tls) {
Node and Thrift