From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/websocket/bufferedamount/index.html | 49 +++++++ files/zh-cn/web/api/websocket/close/index.html | 58 ++++++++ .../zh-cn/web/api/websocket/error_event/index.html | 71 ++++++++++ .../zh-cn/web/api/websocket/extensions/index.html | 43 ++++++ files/zh-cn/web/api/websocket/index.html | 157 +++++++++++++++++++++ .../web/api/websocket/message_event/index.html | 76 ++++++++++ files/zh-cn/web/api/websocket/onclose/index.html | 37 +++++ files/zh-cn/web/api/websocket/onerror/index.html | 45 ++++++ files/zh-cn/web/api/websocket/onmessage/index.html | 49 +++++++ files/zh-cn/web/api/websocket/onopen/index.html | 41 ++++++ files/zh-cn/web/api/websocket/protocol/index.html | 41 ++++++ .../zh-cn/web/api/websocket/readystate/index.html | 60 ++++++++ files/zh-cn/web/api/websocket/send/index.html | 78 ++++++++++ files/zh-cn/web/api/websocket/url/index.html | 51 +++++++ files/zh-cn/web/api/websocket/websocket/index.html | 50 +++++++ .../index.html" | 56 ++++++++ 16 files changed, 962 insertions(+) create mode 100644 files/zh-cn/web/api/websocket/bufferedamount/index.html create mode 100644 files/zh-cn/web/api/websocket/close/index.html create mode 100644 files/zh-cn/web/api/websocket/error_event/index.html create mode 100644 files/zh-cn/web/api/websocket/extensions/index.html create mode 100644 files/zh-cn/web/api/websocket/index.html create mode 100644 files/zh-cn/web/api/websocket/message_event/index.html create mode 100644 files/zh-cn/web/api/websocket/onclose/index.html create mode 100644 files/zh-cn/web/api/websocket/onerror/index.html create mode 100644 files/zh-cn/web/api/websocket/onmessage/index.html create mode 100644 files/zh-cn/web/api/websocket/onopen/index.html create mode 100644 files/zh-cn/web/api/websocket/protocol/index.html create mode 100644 files/zh-cn/web/api/websocket/readystate/index.html create mode 100644 files/zh-cn/web/api/websocket/send/index.html create mode 100644 files/zh-cn/web/api/websocket/url/index.html create mode 100644 files/zh-cn/web/api/websocket/websocket/index.html create mode 100644 "files/zh-cn/web/api/websocket/\344\272\214\350\277\233\345\210\266\347\261\273\345\236\213/index.html" (limited to 'files/zh-cn/web/api/websocket') diff --git a/files/zh-cn/web/api/websocket/bufferedamount/index.html b/files/zh-cn/web/api/websocket/bufferedamount/index.html new file mode 100644 index 0000000000..4162fa92f2 --- /dev/null +++ b/files/zh-cn/web/api/websocket/bufferedamount/index.html @@ -0,0 +1,49 @@ +--- +title: WebSocket.bufferedAmount +slug: Web/API/WebSocket/bufferedAmount +tags: + - API + - Property + - Reference + - Web API + - WebSocket +translation_of: Web/API/WebSocket/bufferedAmount +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.bufferedAmount是一个只读属性,用于返回已经被{{manch("send")}}方法放入队列中但还没有被发送到网络中的数据的字节数。一旦队列中的所有数据被发送至网络,则该属性值将被重置为0。但是,若在发送过程中连接被关闭,则属性值不会重置为0。如果你不断地调用{{manch("send")}},则该属性值会持续增长

+ +

The WebSocket.bufferedAmount read-only property returns the number of bytes of data that have been queued using calls to {{manch("send")}} but not yet transmitted to the network. This value resets to zero once all queued data has been sent. This value does not reset to zero when the connection is closed; if you keep calling {{manch("send")}}, this will continue to climb.

+ +

Syntax

+ +
var bufferedAmount = aWebSocket.bufferedAmount;
+ +

Value

+ +

An unsigned long.

+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-websocket-bufferedamount', 'WebSocket: bufferedAmount')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.WebSocket.bufferedAmount")}}

diff --git a/files/zh-cn/web/api/websocket/close/index.html b/files/zh-cn/web/api/websocket/close/index.html new file mode 100644 index 0000000000..046dd5c079 --- /dev/null +++ b/files/zh-cn/web/api/websocket/close/index.html @@ -0,0 +1,58 @@ +--- +title: WebSocket.close() +slug: Web/API/WebSocket/close +translation_of: Web/API/WebSocket/close +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.close() 方法关闭 {{domxref("WebSocket")}}  连接或连接尝试(如果有的话)。 如果连接已经关闭,则此方法不执行任何操作。

+ +

语法

+ +
WebSocket.close();
+ +

参数

+ +
+
code {{optional_inline}}
+
一个数字状态码,它解释了连接关闭的原因。如果没有传这个参数,默认使用1005。{{domxref("CloseEvent")}}的允许的状态码见状态码列表
+
reason {{optional_inline}}
+
一个人类可读的字符串,它解释了连接关闭的原因。这个UTF-8编码的字符串不能超过123个字节。
+
+ +

抛出的异常

+ +
+
INVALID_ACCESS_ERR
+
一个无效的code
+
SYNTAX_ERR
+
reason 字符串太长(超过123字节)
+
+ +
+

注意: 在Gecko 8.0 {{geckoRelease("8.0")}}之前版本的Gecko里,这个方法不支持传参数。

+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
HTML Living Standard
+ The definition of 'WebSocket.close()' in that specification.
Living StandardInitial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.WebSocket.close")}}

diff --git a/files/zh-cn/web/api/websocket/error_event/index.html b/files/zh-cn/web/api/websocket/error_event/index.html new file mode 100644 index 0000000000..8544e2f399 --- /dev/null +++ b/files/zh-cn/web/api/websocket/error_event/index.html @@ -0,0 +1,71 @@ +--- +title: 'WebSocket: 错误事件' +slug: Web/API/WebSocket/error_event +translation_of: Web/API/WebSocket/error_event +--- +
{{APIRef}}
+ +

websocket的连接由于一些错误事件的发生 (例如无法发送一些数据)而被关闭时,一个error事件将被引发.

+ + + + + + + + + + + + + + + + + + + + +
BubblesNo
CancelableNo
Interface{{domxref("Event")}}
Event handler property{{ domxref("WebSocket.onerror","onerror")}}
+ +

示例

+ +
// Create WebSocket connection
+// 创建一个 WebSocket 连接
+const socket = new WebSocket('ws://localhost:8080');
+
+// Listen for possible errors
+// 监听可能发生的错误
+socket.addEventListener('error', function (event) {
+  console.log('WebSocket error: ', event);
+});
+ +

标准

+ + + + + + + + + + + + + + +
SpecificationStatus
{{SpecName("HTML WHATWG", "web-sockets.html#event-error", "WebSocket error")}}{{Spec2("HTML WHATWG")}}
+ +

浏览器兼容性

+ +

{{Compat("api.WebSocket.error_event")}}

+ +

查看更多

+ + diff --git a/files/zh-cn/web/api/websocket/extensions/index.html b/files/zh-cn/web/api/websocket/extensions/index.html new file mode 100644 index 0000000000..27a66590cc --- /dev/null +++ b/files/zh-cn/web/api/websocket/extensions/index.html @@ -0,0 +1,43 @@ +--- +title: WebSocket.extensions +slug: Web/API/WebSocket/extensions +translation_of: Web/API/WebSocket/extensions +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.extensions是只读属性,返回服务器已选择的扩展值。目前,链接可以协定的扩展值只有空字符串或者一个扩展列表。

+ +

The WebSocket.extensions read-only property returns the extensions selected by the server. This is currently only the empty string or a list of extensions as negotiated by the connection.

+ +

语法

+ +
var extensions = aWebSocket.extensions;
+ +

返回值

+ +

A {{domxref("DOMString")}}.

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-websocket-extensions', 'WebSocket: extensions')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.extensions")}}

diff --git a/files/zh-cn/web/api/websocket/index.html b/files/zh-cn/web/api/websocket/index.html new file mode 100644 index 0000000000..dc534d928a --- /dev/null +++ b/files/zh-cn/web/api/websocket/index.html @@ -0,0 +1,157 @@ +--- +title: WebSocket +slug: Web/API/WebSocket +tags: + - API + - WebSocket + - WebSockets +translation_of: Web/API/WebSocket +--- +
{{APIRef("Web Sockets API")}}
+ +

WebSocket 对象提供了用于创建和管理 WebSocket 连接,以及可以通过该连接发送和接收数据的 API。

+ +

使用 WebSocket() 构造函数来构造一个 WebSocket

+ +

构造函数

+ +
+
{{domxref("WebSocket.WebSocket", "WebSocket(url[, protocols])")}}
+
返回一个 WebSocket 对象。
+
+ +

常量

+ + + + + + + + + + + + + + + + + + + + + + + + +
ConstantValue
WebSocket.CONNECTING0
WebSocket.OPEN1
WebSocket.CLOSING2
WebSocket.CLOSED3
+ +

属性

+ +
+
{{domxref("WebSocket.binaryType")}}
+
使用二进制的数据类型连接。
+
{{domxref("WebSocket.bufferedAmount")}} {{readonlyinline}}
+
未发送至服务器的字节数。
+
+ +
+
{{domxref("WebSocket.extensions")}} {{readonlyinline}}
+
服务器选择的扩展。
+
+ +
+
{{domxref("WebSocket.onclose")}}
+
用于指定连接关闭后的回调函数。
+
{{domxref("WebSocket.onerror")}}
+
用于指定连接失败后的回调函数。
+
{{domxref("WebSocket.onmessage")}}
+
用于指定当从服务器接受到信息时的回调函数。
+
{{domxref("WebSocket.onopen")}}
+
用于指定连接成功后的回调函数。
+
{{domxref("WebSocket.protocol")}} {{readonlyinline}}
+
服务器选择的下属协议。
+
{{domxref("WebSocket.readyState")}} {{readonlyinline}}
+
当前的链接状态。
+
{{domxref("WebSocket.url")}} {{readonlyinline}}
+
WebSocket 的绝对路径。
+
+ +

方法

+ +
+
{{domxref("WebSocket.close", "WebSocket.close([code[, reason]])")}}
+
关闭当前链接。
+
{{domxref("WebSocket.send", "WebSocket.send(data)")}}
+
对要传输的数据进行排队
+
+ +

事件

+ +

使用 addEventListener() 或将一个事件监听器赋值给本接口的 oneventname 属性,来监听下面的事件。

+ +
+
{{domxref("WebSocket/close_event", "close")}}
+
当一个 WebSocket 连接被关闭时触发。
+ 也可以通过 {{domxref("WebSocket/onclose", "onclose")}} 属性来设置。
+
{{domxref("WebSocket/error_event", "error")}}
+
当一个 WebSocket 连接因错误而关闭时触发,例如无法发送数据时。
+ 也可以通过 {{domxref("WebSocket/onerror", "onerror")}} 属性来设置.
+
{{domxref("WebSocket/message_event", "message")}}
+
当通过 WebSocket 收到数据时触发。
+ 也可以通过 {{domxref("WebSocket/onmessage", "onmessage")}} 属性来设置。
+
{{domxref("WebSocket/open_event", "open")}}
+
当一个 WebSocket 连接成功时触发。
+ 也可以通过 {{domxref("WebSocket/onopen", "onopen")}} 属性来设置。
+
+ +

示例

+ +
// Create WebSocket connection.
+const socket = new WebSocket('ws://localhost:8080');
+
+// Connection opened
+socket.addEventListener('open', function (event) {
+    socket.send('Hello Server!');
+});
+
+// Listen for messages
+socket.addEventListener('message', function (event) {
+    console.log('Message from server ', event.data);
+});
+
+ +

规范

+ + + + + + + + + + + + + + +
规范状态注释
{{SpecName("HTML WHATWG", "web-sockets.html#the-websocket-interface", "WebSocket")}}{{Spec2("HTML WHATWG")}}初始定义
+ + + +

浏览器兼容性

+ +

{{Compat("api.WebSocket")}}

+ +

相关链接

+ + + +

+ +

diff --git a/files/zh-cn/web/api/websocket/message_event/index.html b/files/zh-cn/web/api/websocket/message_event/index.html new file mode 100644 index 0000000000..350aac9424 --- /dev/null +++ b/files/zh-cn/web/api/websocket/message_event/index.html @@ -0,0 +1,76 @@ +--- +title: 'WebSocket: message event' +slug: Web/API/WebSocket/message_event +translation_of: Web/API/WebSocket/message_event +--- +
+

{{APIRef}}

+ +

message 事件会在 WebSocket 接收到新消息时被触发。

+ + + + + + + + + + + + + + + + + + + + +
起泡(Bubbles)
可取消
接口{{domxref("MessageEvent")}}
事件处理程序属性{{ domxref("WebSocket.onmessage","onmessage")}}
+ +

例子

+ +
// 创建一个 WebSocket 连接
+const socket = new WebSocket('ws://localhost:8080');
+
+// 监听消息
+socket.addEventListener('message', function (event) {
+    console.log('Message from server ', event.data);
+});
+ +

规范

+ + + + + + + + + + + + + + +
规范状态
{{SpecName("HTML WHATWG", "web-sockets.html#event-message", "WebSocket message")}}{{Spec2("HTML WHATWG")}}
+ +

浏览器兼容性

+ +

{{Compat("api.WebSocket.message_event")}}

+ +

另看

+ + +
+ + diff --git a/files/zh-cn/web/api/websocket/onclose/index.html b/files/zh-cn/web/api/websocket/onclose/index.html new file mode 100644 index 0000000000..0ed1b7ffe1 --- /dev/null +++ b/files/zh-cn/web/api/websocket/onclose/index.html @@ -0,0 +1,37 @@ +--- +title: WebSocket.onclose +slug: Web/API/WebSocket/onclose +translation_of: Web/API/WebSocket/onclose +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.onclose 属性返回一个事件监听器,这个事件监听器将在 WebSocket 连接的{{domxref("WebSocket.readyState","readyState")}} 变为 CLOSED时被调用,它接收一个名字为“close”的 {{domxref("CloseEvent")}} 事件。

+ +

语法

+ +
WebSocket.onclose = function(event) {
+  console.log("WebSocket is closed now.");
+};
+ +

+ +

一个{{domxref("EventListener")}}.

+ +

文档

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#handler-websocket-onclose', 'WebSocket: onclose')}}{{Spec2('HTML WHATWG')}}Initial definition
diff --git a/files/zh-cn/web/api/websocket/onerror/index.html b/files/zh-cn/web/api/websocket/onerror/index.html new file mode 100644 index 0000000000..996ad55472 --- /dev/null +++ b/files/zh-cn/web/api/websocket/onerror/index.html @@ -0,0 +1,45 @@ +--- +title: WebSocket.onerror +slug: Web/API/WebSocket/onerror +translation_of: Web/API/WebSocket/onerror +--- +

{{APIRef("Web Sockets API")}}

+ +

The WebSocket.onerror property returns the event listener to be called when an error occurs. This is a simple event named "error".

+ +

WebSocket.onerror 属性中,你可以定义一个发生错误时执行的回调函数,此事件的事件名为"error"

+ +

语法

+ +
WebSocket.onerror = function(event) {
+  console.error("WebSocket error observed:", event);
+};
+ +

+ +

An {{domxref("EventListener")}}.

+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#handler-websocket-onerror', 'WebSocket: onerror')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.onerror")}}

diff --git a/files/zh-cn/web/api/websocket/onmessage/index.html b/files/zh-cn/web/api/websocket/onmessage/index.html new file mode 100644 index 0000000000..27bcce6cf2 --- /dev/null +++ b/files/zh-cn/web/api/websocket/onmessage/index.html @@ -0,0 +1,49 @@ +--- +title: WebSocket.onmessage +slug: Web/API/WebSocket/onmessage +tags: + - API + - Web API + - WebSocket + - 参考 + - 属性 +translation_of: Web/API/WebSocket/onmessage +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.onmessage 属性是一个当收到来自服务器的消息时被调用的 {{domxref("EventHandler")}}。它由一个{{domxref("MessageEvent")}}调用。

+ +

语法

+ +
aWebSocket.onmessage = function(event) {
+  console.debug("WebSocket message received:", event);
+};
+ +

+ +

一个 {{domxref("EventListener")}}.

+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态注释
{{SpecName('HTML WHATWG', '#handler-websocket-onmessage', 'WebSocket: onmessage')}}{{Spec2('HTML WHATWG')}}初始定义
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.onmessage")}}

diff --git a/files/zh-cn/web/api/websocket/onopen/index.html b/files/zh-cn/web/api/websocket/onopen/index.html new file mode 100644 index 0000000000..067c9057bc --- /dev/null +++ b/files/zh-cn/web/api/websocket/onopen/index.html @@ -0,0 +1,41 @@ +--- +title: WebSocket.onopen +slug: Web/API/WebSocket/onopen +translation_of: Web/API/WebSocket/onopen +--- +

WebSocket.onopen属性定义一个事件处理程序,当{{domxref("WebSocket")}} 的连接状态{{domxref("WebSocket.readyState","readyState")}} 变为{{domxref("WebSocket.readyState","1")}}时调用;这意味着当前连接已经准备好发送和接受数据。这个事件处理程序通过 {{domxref("事件")}}(建立连接时)触发。

+ +

语法

+ +
aWebSocket.onopen = function(event) {
+  console.log("WebSocket is open now.");
+};
+ +

返回值

+ +

An {{domxref("EventListener")}}.

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#handler-websocket-onopen', 'WebSocket: onopen')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.onopen")}}

diff --git a/files/zh-cn/web/api/websocket/protocol/index.html b/files/zh-cn/web/api/websocket/protocol/index.html new file mode 100644 index 0000000000..8a575f1180 --- /dev/null +++ b/files/zh-cn/web/api/websocket/protocol/index.html @@ -0,0 +1,41 @@ +--- +title: WebSocket.protocol +slug: Web/API/WebSocket/protocol +translation_of: Web/API/WebSocket/protocol +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.protocol 是个只读属性,用于返回服务器端选中的子协议的名字;这是一个在创建{{domxref("WebSocket")}} 对象时,在参数{{domxref("protocols")}}中指定的字符串,当没有已建立的链接时为空串。

+ +

语法

+ +
var protocol = aWebSocket.protocol;
+ +

返回值

+ +

DOMString.

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-websocket-protocol', 'WebSocket: protocol')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.protocol")}}

diff --git a/files/zh-cn/web/api/websocket/readystate/index.html b/files/zh-cn/web/api/websocket/readystate/index.html new file mode 100644 index 0000000000..e4d7bd23fb --- /dev/null +++ b/files/zh-cn/web/api/websocket/readystate/index.html @@ -0,0 +1,60 @@ +--- +title: WebSocket.readyState +slug: Web/API/WebSocket/readyState +tags: + - Web API + - WebSocket +translation_of: Web/API/WebSocket/readyState +--- +

{{APIRef("Web Sockets API")}}

+ +

概要

+ +

返回当前 {{domxref("WebSocket")}} 的链接状态,只读。

+ +

语法

+ +
var readyState = WebSocket.readyState;
+ +

+ +

以下其中之一

+ +
+
0 (WebSocket.CONNECTING)
+
正在链接中
+
1 (WebSocket.OPEN)
+
已经链接并且可以通讯
+
2 (WebSocket.CLOSING)
+
连接正在关闭
+
3 (WebSocket.CLOSED)
+
连接已关闭或者没有链接成功
+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
HTML Living Standard
+ The definition of 'WebSocket.readyState' in that specification.
Living StandardInitial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.WebSocket.readyState")}}

+ +

+ +

diff --git a/files/zh-cn/web/api/websocket/send/index.html b/files/zh-cn/web/api/websocket/send/index.html new file mode 100644 index 0000000000..495da7a3e8 --- /dev/null +++ b/files/zh-cn/web/api/websocket/send/index.html @@ -0,0 +1,78 @@ +--- +title: WebSocket.send() +slug: Web/API/WebSocket/send +tags: + - API + - Web API + - WebSocket + - 引用 + - 方法 +translation_of: Web/API/WebSocket/send +--- +

{{APIRef("Web Sockets API")}}

+ + + +

 WebSocket.send() 方法将需要通过 WebSocket 链接传输至服务器的数据排入队列,并根据所需要传输的data bytes的大小来增加 bufferedAmount的值 。若数据无法传输(例如数据需要缓存而缓冲区已满)时,套接字会自行关闭。

+ +

语法

+ +
WebSocket.send("Hello server!");
+ +

参数

+ +
+
data
+
用于传输至服务器的数据。它必须是以下类型之一: +
+
{{domxref("USVString")}}
+
文本字符串。字符串将以 UTF-8 格式添加到缓冲区,并且 bufferedAmount 将加上该字符串以 UTF-8 格式编码时的字节数的值。
+
{{domxref("ArrayBuffer")}}
+
您可以使用一有类型的数组对象发送底层二进制数据;其二进制数据内存将被缓存于缓冲区,bufferedAmount 将加上所需字节数的值。
+
{{domxref("Blob")}}
+
Blob 类型将队列 blob 中的原始数据以二进制中传输。 bufferedAmount 将加上原始数据的字节数的值。
+
{{domxref("ArrayBufferView")}}
+
您可以以二进制帧的形式发送任何 JavaScript 类数组对象 ;其二进制数据内容将被队列于缓冲区中。值 bufferedAmount 将加上必要字节数的值。
+
+
+
+ +

异常

+ +
+
INVALID_STATE_ERR
+
当前连接未处于 OPEN 状态。
+
SYNTAX_ERR
+
数据是一个包含未配对代理(unpaired surrogates)的字符串。
+
+ +
+

Note: Gecko在{{Gecko("6.0")}}中对 send() 方法的实现与规范有些不一致; Gecko 返回一个boolean 来告知当前连接是否依旧处于OPEN 状态 (同时也可以使用该返回值来判定数据是否已经被完全缓存或者传输); 这个问题在 {{Gecko("8.0")}}中被修正.

+ +

而 {{Gecko("11.0")}}, 支持 {{jsxref("ArrayBuffer")}} 类型但不支持 {{domxref("Blob")}}类型.

+
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态注释
{{SpecName('HTML WHATWG', '#dom-websocket-send', 'WebSocket: send')}}{{Spec2('HTML WHATWG')}}初始定义
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.send")}}

diff --git a/files/zh-cn/web/api/websocket/url/index.html b/files/zh-cn/web/api/websocket/url/index.html new file mode 100644 index 0000000000..e28d09a725 --- /dev/null +++ b/files/zh-cn/web/api/websocket/url/index.html @@ -0,0 +1,51 @@ +--- +title: WebSocket.url +slug: Web/API/WebSocket/url +tags: + - API + - Property + - Refrence + - Web API + - WebSocket +translation_of: Web/API/WebSocket/url +--- +

{{APIRef("Web Sockets API")}}

+ +

The WebSocket.url read-only property returns the absolute URL of the {{domxref("WebSocket")}} as resolved by the constructor.

+ +

WebSocket.url是一个只读属性,返回值为当构造函数创建{{domxref("WebSocket")}}实例对象时URL的绝对路径。

+ +

语法

+ +
var url = aWebSocket.url;
+ +

 

+ +

返回值

+ +

A DOMString.

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-websocket-url', 'WebSocket: url')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.url")}}

diff --git a/files/zh-cn/web/api/websocket/websocket/index.html b/files/zh-cn/web/api/websocket/websocket/index.html new file mode 100644 index 0000000000..20977c22ec --- /dev/null +++ b/files/zh-cn/web/api/websocket/websocket/index.html @@ -0,0 +1,50 @@ +--- +title: WebSocket() +slug: Web/API/WebSocket/WebSocket +translation_of: Web/API/WebSocket/WebSocket +--- +

{{APIRef("Web Sockets API")}}
+ WebSocket()构造函器会返回一个 {{domxref("WebSocket")}} 对象。

+ +

语法

+ +
var aWebSocket = new WebSocket(url [, protocols]);
+ +

参数

+ +
+
url
+
要连接的URL;这应该是WebSocket服务器将响应的URL。
+
protocols {{optional_inline}}
+
一个协议字符串或者一个包含协议字符串的数组。这些字符串用于指定子协议,这样单个服务器可以实现多个WebSocket子协议(例如,您可能希望一台服务器能够根据指定的协议(protocol)处理不同类型的交互)。如果不指定协议字符串,则假定为空字符串。
+
+ +

抛出异常

+ +
+
SECURITY_ERR
+
正在尝试连接的端口被阻止。
+
+ +

规范

+ + + + + + + + + + + + + + +
规范状态注释
{{SpecName('HTML WHATWG', '#dom-websocket', 'the WebSocket constructor')}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.WebSocket")}}

diff --git "a/files/zh-cn/web/api/websocket/\344\272\214\350\277\233\345\210\266\347\261\273\345\236\213/index.html" "b/files/zh-cn/web/api/websocket/\344\272\214\350\277\233\345\210\266\347\261\273\345\236\213/index.html" new file mode 100644 index 0000000000..aad8e48fc2 --- /dev/null +++ "b/files/zh-cn/web/api/websocket/\344\272\214\350\277\233\345\210\266\347\261\273\345\236\213/index.html" @@ -0,0 +1,56 @@ +--- +title: WebSocket.binaryType +slug: Web/API/WebSocket/二进制类型 +tags: + - 参考 + - 属性 + - 应用编程接口 + - 网页套接字 + - 网页接口 +translation_of: Web/API/WebSocket/binaryType +--- +

{{APIRef("Web Sockets API")}}

+ +

WebSocket.binaryType 返回websocket连接所传输二进制数据的类型。

+ +

语法

+ +
var binaryType = aWebSocket.binaryType;
+ +

返回值

+ +

 一条{{DOMXref("DOMString")}}:

+ +
+
"blob"
+
如果传输的是 {{domxref("Blob")}} 类型的数据。
+
"arraybuffer"
+
如果传输的是 {{jsxref("ArrayBuffer")}} 类型的数据。 +

 

+
+
+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-websocket-binarytype', 'WebSocket: binaryType')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebSocket.binaryType")}}

-- cgit v1.2.3-54-g00ecf