Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Websockets
  3. socket = io.listen(server);
  4.  
  5. socket.on('connection', function(client){
  6.     console.log(('Client connected: ' + client.sessionId).green.bold);
  7.     client.send('Hello ' + client.sessionId);
  8.  
  9.  
  10.  
  11.     client.on('message', function(message) {
  12.         if (message.text == "hello"){
  13.  
  14.             // ADD A CLIENT
  15.             servers[client.sessionId] = {'counterid' : message.counterid};
  16.             console.log(("\tclient " + client.sessionId + " wants info for counter " + message.counterid).yellow);
  17.             // this is dangerous if we de-couple ids from positions in the array.
  18.             providers[message.counterid - 1].addClient();
  19.  
  20.         }
  21.     });
  22.  
  23.     client.on('disconnect', function() {
  24.         try {
  25.  
  26.             // REMOVE THE CLIENTS
  27.  
  28.             // this is dangerous if we de-couple ids from positions in the array.
  29.             providers[servers[client.sessionId].counterid - 1].removeClient();
  30.             console.log(('Client ' + client.sessionId + ' disconnected. - Stopping Processing for ' + providers[servers[client.sessionId].counterid - 1].host).cyan.bold);
  31.             delete servers[client.sessionId];
  32.            
  33.         } catch (err) {
  34.             console.log((sys.inspect(err)).red);
  35.         }
  36.     });
  37.  
  38. })
  39.  
  40. socket.on('error', function(client) {
  41.     console.log("error!")
  42. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement