title: TcpSocket listen on Firefox addon
body: <p>I'm trying to create a Firefox addon that uses a TcpSocket for communication. I've successfully sent messages through tcp using the following code:</p>
  
  <pre><code>var tcpSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
  var socket = tcpSocket.open("127.0.0.1", 3000);
  socket.onopen = function() {
      socket.send(sendText);
  }
  </code></pre>
  
  <p>That works beautifully.</p>
  
  <p>Now, instead of sending, I want to receive tcp messages. I'm using the following code (based on <a href="https://developer.mozilla.org/en-US/docs/Web/API/TCP_Socket_API" rel="nofollow"><strong>MDN's TCP Socket article</strong></a>)</p>
  
  <pre><code>var tcpSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
  var socket = tcpSocket.listen(3000);
  socket.ondata = function (event) {
      console.log(event);
  };
  </code></pre>
  
  <p>But it logs the following error (in the cmd running <code>cfx run</code>):</p>
  
  <pre><code>console.error: my-addon:
  Object
      - message = Cannot modify properties of a WrappedNative
      - fileName = undefined
      - lineNumber = 6
      ...
  </code></pre>
  
  <p>And, I can say that the port is at least active, because if I ignore the error and try to send a tcp message to that port, the console logs the following:</p>
  
  <pre><code>Received unexpected connection!
  </code></pre>
  
  <p>Am I missing something here? Thanks in advance.</p>