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:
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);
}
That works beautifully.
Now, instead of sending, I want to receive tcp messages. I'm using the following code (based on MDN's 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 the cmd running 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 that port, the console logs the following:
Received unexpected connection!
Am I missing something here? Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…