Creating two separate websocket connections for send and receive on localhost -


i new websockets.

it expected send data(any data) on send websocket connection using port(ex:8000) , localhost should echo same data browser using different websocket connection through different port(ex:9000).

i understand websocket supports full duplex communication on single connection,but above design implement.

question 1) above design possible? question 2) if yes,how create 2 websocket connections(one send , 1 receive) single localhost websocket server?

1) yes.

2) creating 2 separated websockets. different objects though.

you blend both objects in composite object this:

var compositewebsocket = function(urlsend, urlreceive){     var me = {};     var wssend = new websocket(urlsend);     var wsreceive = new websocket(urlreceive);     var open = 0;      wssend.onopen = opening;     wsreceive.onopen = opening;      var opening = function(){         if(open == 2){             if(me.onopen)                 me.onopen();         }         else             open++;     };      var closing = funcion(){         try{wssend.close();}catch(){}         try{wsreceive.close();}catch(){}         if(me.onclose)             me.onclose();     }      me.send = wssend.send;      wsreceive.onmessage = function(msg){         if(me.onmessage)             me.onmessage(msg);     }      return me; } 

(whatch out, code not tested , idea)


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -