I'm currently developing a firefox add-on that is a client who connects using TCP sockets to a server.
In my little test everything works ok, the client(ff add-on) connects to the server(designed in java) and sends a message, but after that firefox is closing the socket.
I know it's not a problem with my code on the server-side , since I can connect with other clients(designed in java and C++) and they never close the connection.
I think the problem is that firefox destroys the socket object after there is no reference to it, therefor closing the connection.
Anyway here is my code:
const {Cc,Ci} = require("chrome");
var host="192.168.1.100";
var port=9001;
var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService)
.createTransport(null, 0, host, port, null);
var inputStream = transport.openInputStream(0, 0, 0);
var inputInterface = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
inputInterface.setInputStream(inputStream);
var outputStream = transport.openOutputStream(0, 0, 0);
var outputInterface = Components.classes["@mozilla.org/binaryoutputstream;1"].createInstance(Components.interfaces.nsIBinaryOutputStream);
outputInterface.setOutputStream(outputStream);
var msg="some message";
outputInterface.writeUtf8Z(msg);
I'm using firefox 7, and I'm building the add-on using firefox add-ons SDK.
Any ideas on how to keep the socket alive , for further readings?
Thanks