--- title: WebSocket.readyState slug: Web/API/WebSocket/readyState tags: - Web API - WebSocket translation_of: Web/API/WebSocket/readyState --- <p>{{APIRef("Web Sockets API")}}</p> <h2 id="概要">概要</h2> <p>返回当前 {{domxref("WebSocket")}} 的链接状态,只读。</p> <h2 id="语法">语法</h2> <pre class="syntaxbox notranslate">var readyState = <em>WebSocket</em>.readyState;</pre> <h2 id="值">值</h2> <p>以下其中之一</p> <dl> <dt>0 (<code>WebSocket.CONNECTING</code>)</dt> <dd>正在链接中</dd> <dt>1 (<code>WebSocket.OPEN</code>)</dt> <dd>已经链接并且可以通讯</dd> <dt>2 (<code>WebSocket.CLOSING</code>)</dt> <dd>连接正在关闭</dd> <dt>3 (<code>WebSocket.CLOSED</code>)</dt> <dd>连接已关闭或者没有链接成功</dd> </dl> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <tbody> <tr> <th>Specification</th> <th>Status</th> <th>Comment</th> </tr> <tr> <td><a class="external external-icon" href="https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-readystate" hreflang="en" lang="en">HTML Living Standard<br> <small lang="en-US">The definition of 'WebSocket.readyState' in that specification.</small></a></td> <td><span class="spec-Living">Living Standard</span></td> <td>Initial definition</td> </tr> </tbody> </table> <h2 id="Browser_compatibility">Browser compatibility</h2> <p>{{Compat("api.WebSocket.readyState")}}</p> <p> <audio class="hidden"></audio> </p>