chrome.socket 'data' event

January 12, 2013

Having previously worked with sockets in node.js I expected the chrome.socket api to have a 'data' event similar to the one in node.js net.Socket, however this is not the case. This event is emmited when new data is available to be read.

To emulate the node.js socket behaviour in chrome.socket I suggest using this workaround:

function onReadHandler(readInfo) {
     // do things with data
     // ....

     // re register handler with callback itself,null,onReadHandler);         

I tried looking for better alternatives on Stack Overflow but this appears to be the best solution