javascript - Websocket timeout -
i need handle websocket timeout when socket trying connect server available busy.
more in deep have web application can connect several single-thread remote socket server in charge post-process data passed input.
the goal collect data web gui , submit them first socket available , listening.
in case server socket daemon processing data, cannot serve user request has instead addressed second socket of list.
basically , practical example, have such socket ready accept call coming web brworser:
ws://10.20.30.40:8080/ ws://10.20.30.40:8081/ ws://10.20.30.40:8082/ ws://10.20.30.40:8083/ ws://192.192.192.192:9001/
when first socket receive call , perform handshake, starts process data (and process may took minutes).
when client same request on different set of data, that request served 2nd socket available , on.
so question is... how can contact socket (the first of list), wait 250 milliseconds , (in case of timeout) skip next one?
i've started following approach:
$.interval = function(func, wait, times) { var interv = function(w, t) { return function() { if (typeof t === "undefined" || t-- > 0) { settimeout(interv, w); try { func.call(null); } catch(e) { t = 0; throw e.tostring(); } } else { alert('stop'); } }; } (wait, times); settimeout(interv, wait); } handler = new websocket(url); loop = 1; $.interval(function(){ rs = handler.readystate; console.log("(" + loop++ + ") readystate: " + rs); }, 25, 10); //loop 10 times every 25 milliseconds
but how can stop in case socket.readystate became 1 (open) or limit reached?
Comments
Post a Comment