var io = require('socket.io')(8987);
var clients = {};
var usercount = 0;

io.on('connection', function(socket) {
  var currentUserId;
  currentUserId = ++usercount;
  clients[currentUserId] = socket;

  // 握手
  socket.emit('server-ok', {
    userid: currentUserId,
    msg: `user${usercount}成功连接到服务器`
  });

  socket.on('client-ok', function(data) {
    socket.broadcast.emit('new message', {
      userid: currentUserId,
      msg: `Hello World!`
    });
    console.log(data.msg);
  });


  socket.on('get user lists', function(){

    socket.emit('new message', {
      userid: 'server',
      msg: `[${Object.keys(clients)}]`
    });
  });



  socket.on('disconnect', function() {
    console.log(`user${currentUserId}失去连接`);
    delete clients[currentUserId];
    io.emit('user disconnected', {
      userid: currentUserId
    });
  });
});

@@ -201,13 +201,174 @@
 %0A%0A  
-// %E6%8F%A1%E6%89%8B
+remoteOk(currentUserId);%0A  getUserLists(currentUserId);%0A  disconnected(currentUserId);%0A%0A%7D);%0A%0Afunction remoteOk(currentUserId)%7B%0A  var socket = clients%5BcurrentUserId%5D;%0A
 %0A  s
@@ -644,16 +644,96 @@
 ;%0A  %7D);%0A
+%7D%0A%0A%0Afunction getUserLists(currentUserId)%7B%0A  var socket = clients%5BcurrentUserId%5D;
 %0A%0A  sock
@@ -768,17 +768,16 @@
 tion()%7B%0A
-%0A
     sock
@@ -878,17 +878,95 @@
 ;%0A  %7D);%0A
-%0A
+%7D%0A%0Afunction disconnected(currentUserId)%7B%0A  var socket = clients%5BcurrentUserId%5D;
 %0A%0A  sock
@@ -1156,11 +1156,9 @@
 %0A  %7D);%0A%7D
-);
 %0A

refactor server