[JavaScript] websockets的bufferedAmount使用范例代码 →→→→→进入此内容的聊天室

来自 , 2019-10-16, 写在 JavaScript, 查看 166 次.
URL http://www.code666.cn/view/a440a3d3
  1. // 10k max buffer size.
  2. var THRESHOLD = 10240;
  3.  
  4. // Create a New WebSocket connection
  5. var ws = new WebSocket("ws://w3mentor.com");
  6.  
  7. // Listen for the opening event
  8. ws.onopen = function () {
  9.  
  10.    // Attempt to send update every second.
  11.    setInterval( function() {
  12.       // Send only if the buffer is not full
  13.       if (ws.bufferedAmount < THRESHOLD) {
  14.          ws.send(getApplicationState());
  15.       }
  16.    }, 1000);
  17. };
  18. //javascript/7239

回复 "websockets的bufferedAmount使用范例代码"

这儿你可以回复上面这条便签

captcha