最新消息:

socket.io

服务端 luther 342浏览 0评论
if(socket.handshake.headers['x-forwarded-for'] != null){
    ip = socket.handshake.headers['x-forwarded-for'];
}else{
    ip = socket.handshake.address;
}
———————————————-
let socket = null;

function connect_socket() {
  socket = new WebSocket(ws_url);
  socket.on("close", connect_socket); // <- rise from your grave!
  heartbeat();
}

function heartbeat() {
  if (!socket) return;
  if (socket.readyState !== 1) return;
  socket.send("heartbeat");
  setTimeout(heartbeat, 500);
}

connect_socket();

转载请注明:应用享评 » socket.io

您必须 登录 才能发表评论!