javascript - establish send property for multiple webscoket connections -


in script below try open ten websocket connections server:

 var webscd=[];  function initweb(){     (var c=0; c <10; c++){        webscd[c]=new websocket(wsadress);        webscd[c].onopen=function(evt){         var binary = new uint8array(2);         binary[0]=1;         binary[1]=2;         webscd[c].send(binary.buffer);                         };       webscd[c].onclose=function(evt){};       webscd[c].onmessage=function(evt){};       webscd[c].onerror=function(evt){};     }  }  initweb(); 

but script throws following error

'uncaught typeerror: cannot read property 'send' of undefined'

. should do?

i figured out way without closure stuff.

function create_ws() {   var ws=new websocket("ws://127.0.0.1:1234");   ws.onopen=function(evt){     var binary = new uint8array(2);     binary[0]=1;     binary[1]=2;     ws.send(binary.buffer);                     };   ws.onclose=function(evt){};   ws.onmessage=function(evt){};   ws.onerror=function(evt){}; }  var webscd = [];  for(var = 0; < 10; i++) {   webscd.push(create_ws()); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -