zoukankan      html  css  js  c++  java
  • WebSocket对象的“readyState”属性记录连接过程中的状态值

    websocket的两个属性:readyState和bufferedAmount。

     

     

    根据readyState属性可以判断webSocket的连接状态,该属性的值可以是下面几种:
    0 :对应常量CONNECTING (numeric value 0),
     正在建立连接连接,还没有完成。The connection has not yet been established.
     
    1 :对应常量OPEN (numeric value 1),
     连接成功建立,可以进行通信。The WebSocket connection is established and communication is possible.
     
    2 :对应常量CLOSING (numeric value 2)
     连接正在进行关闭握手,即将关闭。The connection is going through the closing handshake.
     
    3 : 对应常量CLOSED (numeric value 3)
     连接已经关闭或者根本没有建立。The connection has been closed or could not be opened.
     
    例:
    var socket = new WebSocket(url);
    if(socket.readyState!=1){
    alert("未连接。");
    return;
    }
     
    根据bufferedAmount可以知道有多少字节的数据等待发送,若websocket已经调用了close方法则该属性将一直增长。
  • 相关阅读:
    洛谷7月月赛 B 题解
    undone
    树剖学习
    关于两周后noip---小计划
    线段树技巧练习--GSS1
    链式前向星存图及注意要点
    错题集合
    树上差分问题
    2020暑假学习内容整理及后续计划
    安利大佬博客
  • 原文地址:https://www.cnblogs.com/ertingbo/p/9413243.html
Copyright © 2011-2022 走看看