You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Matias Hernandez Arellano <ms...@archlinux.cl> on 2011/05/31 16:53:25 UTC
Connection refused (server js/ client c++)
(sorry for my english) Hi, i trying to build a little implementation where i have a C++ client and a nodejs server.
The server receive information about an image.
The client create an imagen an send to the server.
The client run the creation process in a thread inside a loop, in this loop, when a image is ready i call a thrift method to send the image to the server.
But!!.. in the server side i can't receive the data (just null) and in the client side i see an error (inside a try...catch ):Thrift: Tue May 31 10:42:45 2011 TSocket::open() connect() <Host: localhost Port: 9090>Connection refused
The connection is refused, but in both process (client/server) the same port and host is used. Sometimes (at randome) theres no connection and no error, the client just "stalt" in the thrift thread. any idea?
some code:
Server (nodejs):
var thrift = require('thrift');
var ImageService = require('./ImageService.js'),
ttypes = require('./service_types.js');
var server = thrift.createServer(ImageService,{
receiveImage: function(image,success){
console.log("Height: ", image.height);
success(true);
},
});
server.listen(9090);
Client (c++):
//Constructor
static ImageServiceClient *client;
shared_ptr<TTransport> tr;
StreamThread::StreamThread(Utils::CircularBuffer<cv::Mat>**buffer){
this->bufferProcesado = *buffer;
shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
shared_ptr<TTransport> transport(new TFramedTransport(socket));
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
client = new ImageServiceClient(protocol);
tr = transport;
}
//run method of the thread
void StreamThread::run(){
MyImage imagen;
while(this->bufferProcesado->actual_size()!=0){
this->bufferProcesado->pop_back(&imagen);
try{
tr->open();
ImageData data;
data.data = imagen.data
data.height = imagen.height();
data.width = imagen.width();
if(client->receiveImage(data))
std::cout << "True" << std::endl;
else
std::cout << "False" << std::endl;
tr->close();
}catch(std::exception &e){
std::cerr << "Error: " << e.what() << std::endl;
}
}
}
MatÃas Hernandez Arellano
Ingeniero de Software/Proyectos en VisionLabs S.A
CDA Archlinux-CL
www.msdark.archlinux.cl