title: Opening TCP socket from Firefox plugin
body: <p>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.</p>
  
  <p>I have checked and no firewalls are running, and if I set netcat to listen on my desired port <em>before</em> launching this plugin, it behaves differently (it will print "opened port!"). Unfortunately I really am trying to have the plugin be the listener/server.</p>
  
  <pre><code>//TCPSocket API: https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket
  //Got me started: http://stackoverflow.com/q/28326301
  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!');}
  </code></pre>
  
  <p>Right now though the immediate output is:</p>
  
  <pre><code>console.log: my-addon: port error!
  console.log: my-addon: DOMError {}
  console.log: my-addon: port closed!
  </code></pre>
  
  <p>where "DOMError" is the error received by socket.onerror.</p>
  
  <p>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.</p>