javascript - Find current client (websocket) -


i using following code save clients in array...

var websocketserver = require('ws').server, wss = new websocketserver({port: 8080}), clients=[];  wss.on('connection', function(ws) {     clients.push(ws);     ws.on('message', function(message) {         console.log('received: %s', message);         findclient(message);     });     ws.send("new user joined"); });  function findclient (message) {     (var i=0; i<clients.length; i++) {         //this i'm stuck         if current client return     }  } 

i not know put inside loop find current client. want iterate through array, , if current client == 1 of client in array, want return index.

i'm sure there simple way this, stuck.

do findclient(ws) -- have ws (socket) belonging particular client bound closure of message event handler. findclient function becomes:

function getclientindex(socket) {   return clients.indexof(socket); } 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -