I am working on a firefox-os app that tries to connect to a list of IP's in sequence through the TCP Socket API.
However, I would like to close the socket if it doesn't connect within a few seconds, and also if the connection is inactive for more than a few seconds.
Example:
var socket = navigator.mozTCPSocket.open(IP, port);
//would like to set timeout for connection here
socket.onopen = function(event){
var serviceRequest = new Object();
serviceRequest.type = "myService";
var sendStr = JSON.stringify(serviceRequest);
sendStr+="\n";
sendStr = sendStr.toString('utf-8');
socket.send(sendStr);
//and would like a timeout for receiving data here
socket.ondata = function(event){
//etc
}
}