I'm afraid I'm having trouble opening a socket from my Firefox plugin. My goal is to have my plugin listen on the port, and a Python script will send it a short string once in a while to act on.
I have checked and no firewalls are running, and if I set netcat to listen on my desired port before launching this plugin, it behaves differently (it will print "opened port!"). Unfortunately I really am trying to have the plugin be the listener/server.
//TCPSocket API: https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket
//Got me started: https://mcmap.net/q/1774031/-tcpsocket-listen-on-firefox-addon
const {Cu,Cc,Ci} = require("chrome");
var tcpSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
var socket = tcpSocket.open("127.0.0.1", 64515);
socket.ondata = function (event) {
console.log('port received data!!!');
if (typeof event.data === 'string') {
console.log('Got: ' + event.data);
}
}
socket.onopen = function() {console.log('opened port!');}
socket.onerror = function(event) {
console.log('port error!');
console.log(event.data)
}
socket.onclose = function() {console.log('port closed!');}
socket.ondrain = function() {console.log('port drained!');}
Right now though the immediate output is:
console.log: my-addon: port error!
console.log: my-addon: DOMError {}
console.log: my-addon: port closed!
where "DOMError" is the error received by socket.onerror.
I'm unsure whether this is my lack of understanding sockets or if there is something special to do with Firefox addons and permissions when it comes to opening a port.