I am trying to create a Firefox addon that uses TcpSocket for communication. I successfully sent messages via tcp using the following 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);
}
It works great.
Now, instead of sending, I want to receive tcp messages. I am using the following code (based on MDN TCP Socket article )
var tcpSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
var socket = tcpSocket.listen(3000);
socket.ondata = function (event) {
console.log(event);
};
But it logs the following error (in cmd startup cfx run):
console.error: my-addon:
Object
- message = Cannot modify properties of a WrappedNative
- fileName = undefined
- lineNumber = 6
...
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 this port, the console logs the following:
Received unexpected connection!
Am I missing something? Thanks in advance.
source
share