Reputation: 2429
I'm trying to set up a TCP server in a Chrome app. I'm very close to being done. I can send data from my TCP server to my client. But I can't process the data sent BY the client. I figured out that the socket is paused. The thing is, I can't seem to un-pause it.
If I try this in the JavaScript console:
chrome.sockets.tcp.getSockets(function(d) {console.log(d);});
I get this result:
[Object]
0: Object
connected: true
localAddress: "127.0.0.1"
localPort: 60519
paused: true
peerAddress: "127.0.0.1"
peerPort: 36529
persistent: false
socketId: 11
length: 1
So then I just unpause it, right? Like this:
chrome.sockets.tcpServer.setPaused(
socketID, false, function () {
console.log('unpaused');
}
);
And indeed my callback is run:
unpaused
But if I check again
chrome.sockets.tcp.getSockets(function(d) {console.log(d);});
I still get:
[Object]
0: Object
connected: true
localAddress: "127.0.0.1"
localPort: 60519
paused: true
peerAddress: "127.0.0.1"
peerPort: 36529
persistent: false
socketId: 11
length: 1
For the socketID value in the call to setPaused, I've used both the value Chrome gave me for socketID and for clientSocketID. Neither one seems to unpause my socket.
EDIT:
I also tried getInfo():
chrome.sockets.tcpServer.getInfo(19, function (d) {console.log(d);});
which returned, to my great surprise:
Object {
localAddress: "127.0.0.1",
localPort: 60519,
paused: false,
persistent: false,
socketId: 19
}
getSockets() still says that the socket is paused. The socket is still not receiving messages. I'm very confused.
For the sake of completeness, here's how I'm trying to process messages:
Package.MyClass.prototype.onAccept = function(info) {
console.log('accept info', info);
if (info.socketId !== this.serverSocketId) { return;}
console.log('Socket ID is correct.'); // This gets printed every time.
// Start receiving data.
chrome.sockets.tcp.onReceive.addListener(this.onReceive.bind(this));
chrome.sockets.tcpServer.setPaused(this.serverSocketId, false);
}
I can tell that onAccept() is called when the client connects to the socket: the console log shows that. But onReceive also starts with a call to console.log and that never shows up.
EDIT: SOLVED:
I found a workaround: I used this script instead: https://github.com/GoogleChrome/chrome-app-samples/blob/master/tcpserver/tcp-server.js
It does everything I need and it's much easier to use and configure.
Upvotes: 1
Views: 660
Reputation: 2429
As mentioned in my final edit, I found a workaround: I used this script instead: https://github.com/GoogleChrome/chrome-app-samples/blob/master/tcpserver/tcp-server.js
It does everything I need and it's much easier to use and configure.
It just seems that the built-in TCP server is not functional as per the current version of Chrome, Chrome 34.
Upvotes: 1