I'm developing a Firefox add-on with Jetpack and I need to implement a communication between the add-on and a server written in Java. The communication must be opened when the add-on starts and then every time that the add-on needs it, it makes a request to the server. But it must be Synchronous because it needs the server response in order to continue executing.
I've been looking for examples of synchronous sockets in javascript but I didn't get results. May be it can be done by asynchronous code, but I don't know how to.
EDIT: Here is the code of my add-on (using jetpack-net library):
var net = require('net');
var Server = function() {
this.socket = net.createConnection(6666, 'localhost');
this.socket.on('data', function(data) {
console.log(data.replace(/\n/gm," "));
}).on('connect', function() {
//console.log('Socket connected.');
}).on('end', function() {
//console.log('Connection finished.');
});
this.findCategory = function(query) {
this.socket.write(query + "\n");
}
}
exports.main = function() {
var gs = new Server();
processResult(gs.findCategory('Bye'));
};