Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
5ed0c454
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5ed0c454
编写于
4月 29, 2023
作者:
X
xujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
js-docs整改
Signed-off-by:
N
xujie
<
xujie223@huawei.com
>
上级
c5356dc1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
137 addition
and
150 deletion
+137
-150
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
.../application-dev/reference/apis/js-apis-net-connection.md
+27
-27
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
+14
-14
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
+28
-28
zh-cn/application-dev/reference/apis/js-apis-socket.md
zh-cn/application-dev/reference/apis/js-apis-socket.md
+50
-62
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
+18
-19
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
浏览文件 @
5ed0c454
...
...
@@ -11,7 +11,7 @@
import
connection
from
'
@ohos.net.connection
'
```
## connection.createNetConnection
## connection.createNetConnection
<sup>8+</sup>
createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection
...
...
@@ -46,7 +46,7 @@ let netConnectionCellular = connection.createNetConnection({
})
```
## connection.getDefaultNet
## connection.getDefaultNet
<sup>8+</sup>
getDefaultNet(callback: AsyncCallback
\<
NetHandle>): void
...
...
@@ -79,7 +79,7 @@ connection.getDefaultNet(function (error, data) {
})
```
## connection.getDefaultNet
## connection.getDefaultNet
<sup>8+</sup>
getDefaultNet(): Promise
\<
NetHandle>
...
...
@@ -444,7 +444,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getAllNets
## connection.getAllNets
<sup>9+</sup>
getAllNets(callback: AsyncCallback
<
Array
<
NetHandle
>>
): void
...
...
@@ -477,7 +477,7 @@ connection.getAllNets(function (error, data) {
});
```
## connection.getAllNets
## connection.getAllNets
<sup>9+</sup>
getAllNets(): Promise
<
Array
<
NetHandle
>>
...
...
@@ -509,7 +509,7 @@ connection.getAllNets().then(function (data) {
});
```
## connection.getConnectionProperties
## connection.getConnectionProperties
<sup>9+</sup>
getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback
\<
ConnectionProperties>): void
...
...
@@ -547,7 +547,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getConnectionProperties
## connection.getConnectionProperties
<sup>9+</sup>
getConnectionProperties(netHandle: NetHandle): Promise
\<
ConnectionProperties>
...
...
@@ -589,7 +589,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getNetCapabilities
## connection.getNetCapabilities
<sup>9+</sup>
getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback
\<
NetCapabilities>): void
...
...
@@ -627,7 +627,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getNetCapabilities
## connection.getNetCapabilities
<sup>9+</sup>
getNetCapabilities(netHandle: NetHandle): Promise
\<
NetCapabilities>
...
...
@@ -734,7 +734,7 @@ connection.isDefaultNetMetered().then(function (data) {
})
```
## connection.hasDefaultNet
## connection.hasDefaultNet
<sup>9+</sup>
hasDefaultNet(callback: AsyncCallback
\<
boolean>): void
...
...
@@ -767,7 +767,7 @@ connection.hasDefaultNet(function (error, data) {
})
```
## connection.hasDefaultNet
## connection.hasDefaultNet
<sup>9+</sup>
hasDefaultNet(): Promise
\<
boolean>
...
...
@@ -799,7 +799,7 @@ connection.hasDefaultNet().then(function (data) {
})
```
## connection.enableAirplaneMode
## connection.enableAirplaneMode
<sup>9+</sup>
enableAirplaneMode(callback: AsyncCallback
\<
void>): void
...
...
@@ -832,7 +832,7 @@ connection.enableAirplaneMode(function (error) {
})
```
## connection.enableAirplaneMode
## connection.enableAirplaneMode
<sup>9+</sup>
enableAirplaneMode(): Promise
\<
void>
...
...
@@ -865,7 +865,7 @@ connection.enableAirplaneMode().then(function (error) {
})
```
## connection.disableAirplaneMode
## connection.disableAirplaneMode
<sup>9+</sup>
disableAirplaneMode(callback: AsyncCallback
\<
void>): void
...
...
@@ -898,7 +898,7 @@ connection.disableAirplaneMode(function (error) {
})
```
## connection.disableAirplaneMode
## connection.disableAirplaneMode
<sup>9+</sup>
disableAirplaneMode(): Promise
\<
void>
...
...
@@ -931,7 +931,7 @@ connection.disableAirplaneMode().then(function (error) {
})
```
## connection.reportNetConnected
## connection.reportNetConnected
<sup>9+</sup>
reportNetConnected(netHandle: NetHandle, callback: AsyncCallback
<
void
>
): void
...
...
@@ -968,7 +968,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetConnected
## connection.reportNetConnected
<sup>9+</sup>
reportNetConnected(netHandle: NetHandle): Promise
<
void
>
...
...
@@ -1009,7 +1009,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetDisconnected
## connection.reportNetDisconnected
<sup>9+</sup>
reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback
<
void
>
): void
...
...
@@ -1046,7 +1046,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetDisconnected
## connection.reportNetDisconnected
<sup>9+</sup>
reportNetDisconnected(netHandle: NetHandle): Promise
<
void
>
...
...
@@ -1087,7 +1087,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.getAddressesByName
## connection.getAddressesByName
<sup>9+</sup>
getAddressesByName(host: string, callback: AsyncCallback
\<
Array
\<
NetAddress>>): void
...
...
@@ -1124,7 +1124,7 @@ connection.getAddressesByName(host, function (error, data) {
})
```
## connection.getAddressesByName
## connection.getAddressesByName
<sup>9+</sup>
getAddressesByName(host: string): Promise
\<
Array
\<
NetAddress>>
...
...
@@ -1174,7 +1174,7 @@ connection.getAddressesByName(host).then(function (data) {
> 设备从有网络到无网络状态会触发netLost事件;
> 设备从WiFi到蜂窝会触发netLost事件(WiFi丢失)之后触发 netAvaliable事件(蜂窝可用);
### register
### register
<sup>10+</sup>
register(callback: AsyncCallback
\<
void>): void
...
...
@@ -1208,7 +1208,7 @@ netConnection.register(function (error) {
})
```
### unregister
### unregister
<sup>10+</sup>
unregister(callback: AsyncCallback
\<
void>): void
...
...
@@ -1640,7 +1640,7 @@ connection.getDefaultNet().then((netHandle) => {
})
```
### getAddressesByName
### getAddressesByName
<sup>9+</sup>
getAddressesByName(host: string, callback: AsyncCallback
\<
Array
\<
NetAddress>>): void
...
...
@@ -1679,7 +1679,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressesByName
### getAddressesByName
<sup>9+</sup>
getAddressesByName(host: string): Promise
\<
Array
\<
NetAddress>>
...
...
@@ -1722,7 +1722,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressByName
### getAddressByName
<sup>9+</sup>
getAddressByName(host: string, callback: AsyncCallback
\<
NetAddress>): void
...
...
@@ -1761,7 +1761,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressByName
### getAddressByName
<sup>9+</sup>
getAddressByName(host: string): Promise
\<
NetAddress>
...
...
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
浏览文件 @
5ed0c454
...
...
@@ -11,7 +11,7 @@
import
ethernet
from
'
@ohos.net.ethernet
'
```
## ethernet.setIfaceConfig
## ethernet.setIfaceConfig
<sup>9+</sup>
setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback
\<
void>): void
...
...
@@ -64,7 +64,7 @@ ethernet.setIfaceConfig("eth0", {
});
```
## ethernet.setIfaceConfig
## ethernet.setIfaceConfig
<sup>9+</sup>
setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise
\<
void>
...
...
@@ -120,7 +120,7 @@ ethernet.setIfaceConfig("eth0", {
});
```
## ethernet.getIfaceConfig
## ethernet.getIfaceConfig
<sup>9+</sup>
getIfaceConfig(iface: string, callback: AsyncCallback
\<
InterfaceConfiguration>): void
...
...
@@ -168,7 +168,7 @@ ethernet.getIfaceConfig("eth0", (error, value) => {
});
```
## ethernet.getIfaceConfig
## ethernet.getIfaceConfig
<sup>9+</sup>
getIfaceConfig(iface: string): Promise
\<
InterfaceConfiguration>
...
...
@@ -219,7 +219,7 @@ ethernet.getIfaceConfig("eth0").then((data) => {
});
```
## ethernet.isIfaceActive
## ethernet.isIfaceActive
<sup>9+</sup>
isIfaceActive(iface: string, callback: AsyncCallback
\<
number>): void
...
...
@@ -261,7 +261,7 @@ ethernet.isIfaceActive("eth0", (error, value) => {
});
```
## ethernet.isIfaceActive
## ethernet.isIfaceActive
<sup>9+</sup>
isIfaceActive(iface: string): Promise
\<
number>
...
...
@@ -306,7 +306,7 @@ ethernet.isIfaceActive("eth0").then((data) => {
});
```
## ethernet.getAllActiveIfaces
## ethernet.getAllActiveIfaces
<sup>9+</sup>
getAllActiveIfaces(callback: AsyncCallback
\<
Array
\<
string>>): void
...
...
@@ -347,7 +347,7 @@ ethernet.getAllActiveIfaces((error, value) => {
});
```
## ethernet.getAllActiveIfaces
## ethernet.getAllActiveIfaces
<sup>9+</sup>
getAllActiveIfaces(): Promise
\<
Array
\<
string>>
...
...
@@ -403,7 +403,7 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 |
| callback | Callback
\<
{ iface: string, active: boolean }
\>
| 是 | 回调函数。
<br>
iface:网卡名称。
<br>
active:是否处于激活状态(true:激活;false:未激活) |
| callback |
Async
Callback
\<
{ iface: string, active: boolean }
\>
| 是 | 回调函数。
<br>
iface:网卡名称。
<br>
active:是否处于激活状态(true:激活;false:未激活) |
**错误码:**
...
...
@@ -416,8 +416,8 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo
**示例:**
```
js
ethernet
.
on
(
'
interfaceStateChange
'
,
(
data
)
=>
{
console
.
log
(
'
on interfaceSharingStateChange:
'
+
JSON
.
stringify
(
data
.
iface
)
+
JSON
.
stringify
(
data
.
active
));
ethernet
.
on
(
'
interfaceStateChange
'
,
(
data
)
=>
{
console
.
log
(
'
on interfaceSharingStateChange:
'
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -438,7 +438,7 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 |
| callback | Callback
\<
{ iface: string, active: boolean }> | 否 | 回调函数。
<br>
iface:网卡名称。
<br>
active:是否处于激活状态(true:激活;false:未激活) |
| callback |
Async
Callback
\<
{ iface: string, active: boolean }> | 否 | 回调函数。
<br>
iface:网卡名称。
<br>
active:是否处于激活状态(true:激活;false:未激活) |
**错误码:**
...
...
@@ -454,7 +454,7 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active:
ethernet
.
off
(
'
interfaceStateChange
'
);
```
## InterfaceConfiguration
## InterfaceConfiguration
<sup>9+</sup>
以太网连接配置网络信息。
...
...
@@ -471,7 +471,7 @@ ethernet.off('interfaceStateChange');
| netMask | string | 是 | 以太网连接配置子网掩码,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 |
| dnsServers | string | 是 | 以太网连接配置dns服务地址,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)多地址间用“,”隔开。 |
## IPSetMode
## IPSetMode
<sup>9+</sup>
以太网连接模式。
...
...
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
浏览文件 @
5ed0c454
...
...
@@ -12,7 +12,7 @@
import
sharing
from
'
@ohos.net.sharing
'
```
## sharing.isSharingSupported
## sharing.isSharingSupported
<sup>9+</sup>
isSharingSupported(callback: AsyncCallback
\<
boolean>): void
...
...
@@ -48,7 +48,7 @@ sharing.isSharingSupported((error, data) => {
});
```
## sharing.isSharingSupported
## sharing.isSharingSupported
<sup>9+</sup>
isSharingSupported(): Promise
\<
boolean>
...
...
@@ -85,7 +85,7 @@ sharing.isSharingSupported().then(data => {
});
```
## sharing.isSharing
## sharing.isSharing
<sup>9+</sup>
isSharing(callback: AsyncCallback
\<
boolean>): void
...
...
@@ -120,7 +120,7 @@ sharing.isSharing((error, data) => {
});
```
## sharing.isSharing
## sharing.isSharing
<sup>9+</sup>
isSharing(): Promise
\<
boolean>
...
...
@@ -156,7 +156,7 @@ sharing.isSharing().then(data => {
});
```
## sharing.startSharing
## sharing.startSharing
<sup>9+</sup>
startSharing(type: SharingIfaceType, callback: AsyncCallback
\<
void>): void
...
...
@@ -201,7 +201,7 @@ sharing.startSharing(SHARING_WIFI, (error) => {
});
```
## sharing.startSharing
## sharing.startSharing
<sup>9+</sup>
startSharing(type: SharingIfaceType): Promise
\<
void>
...
...
@@ -253,7 +253,7 @@ sharing.startSharing(SHARING_WIFI).then(() => {
});
```
## sharing.stopSharing
## sharing.stopSharing
<sup>9+</sup>
stopSharing(type: SharingIfaceType, callback: AsyncCallback
\<
void>): void
...
...
@@ -296,7 +296,7 @@ sharing.stopSharing(SHARING_WIFI, (error) => {
});
```
## sharing.stopSharing
## sharing.stopSharing
<sup>9+</sup>
stopSharing(type: SharingIfaceType): Promise
\<
void>
...
...
@@ -346,7 +346,7 @@ sharing.stopSharing(SHARING_WIFI).then(() => {
});
```
## sharing.getStatsRxBytes
## sharing.getStatsRxBytes
<sup>9+</sup>
getStatsRxBytes(callback: AsyncCallback
\<
number>): void
...
...
@@ -381,7 +381,7 @@ sharing.getStatsRxBytes((error, data) => {
});
```
## sharing.getStatsRxBytes
## sharing.getStatsRxBytes
<sup>9+</sup>
getStatsRxBytes(): Promise
\<
number>
...
...
@@ -417,7 +417,7 @@ sharing.getStatsRxBytes().then(data => {
});
```
## sharing.getStatsTxBytes
## sharing.getStatsTxBytes
<sup>9+</sup>
getStatsTxBytes(callback: AsyncCallback
\<
number>): void
...
...
@@ -452,7 +452,7 @@ sharing.getStatsTxBytes((error, data) => {
});
```
## sharing.getStatsTxBytes
## sharing.getStatsTxBytes
<sup>9+</sup>
getStatsTxBytes(): Promise
\<
number>
...
...
@@ -488,7 +488,7 @@ sharing.getStatsTxBytes().then(data => {
});
```
## sharing.getStatsTotalBytes
## sharing.getStatsTotalBytes
<sup>9+</sup>
getStatsTotalBytes(callback: AsyncCallback
\<
number>): void
...
...
@@ -523,7 +523,7 @@ sharing.getStatsTotalBytes((error, data) => {
});
```
## sharing.getStatsTotalBytes
## sharing.getStatsTotalBytes
<sup>9+</sup>
getStatsTotalBytes(): Promise
\<
number>
...
...
@@ -559,7 +559,7 @@ sharing.getStatsTotalBytes().then(data => {
});
```
## sharing.getSharingIfaces
## sharing.getSharingIfaces
<sup>9+</sup>
getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback
\<
Array
\<
string>>): void
...
...
@@ -600,7 +600,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH, (error, data) => {
});
```
## sharing.getSharingIfaces
## sharing.getSharingIfaces
<sup>9+</sup>
getSharingIfaces(state: SharingIfaceState): Promise
\<
Array
\<
string>>
...
...
@@ -647,7 +647,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH).then(data => {
});
```
## sharing.getSharingState
## sharing.getSharingState
<sup>9+</sup>
getSharingState(type: SharingIfaceType, callback: AsyncCallback
\<
SharingIfaceState>): void
...
...
@@ -688,7 +688,7 @@ sharing.getSharingState(SHARING_WIFI, (error, data) => {
});
```
## sharing.getSharingState
## sharing.getSharingState
<sup>9+</sup>
getSharingState(type: SharingIfaceType): Promise
\<
SharingIfaceState>
...
...
@@ -735,7 +735,7 @@ sharing.getSharingState(SHARING_WIFI).then(data => {
});
```
## sharing.getSharableRegexes
## sharing.getSharableRegexes
<sup>9+</sup>
getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback
\<
Array
\<
string>>): void
...
...
@@ -776,7 +776,7 @@ sharing.getSharableRegexes(SHARING_WIFI, (error, data) => {
});
```
## sharing.getSharableRegexes
## sharing.getSharableRegexes
<sup>9+</sup>
getSharableRegexes(type: SharingIfaceType): Promise
\<
Array
\<
string>>
...
...
@@ -823,7 +823,7 @@ sharing.getSharableRegexes(SHARING_WIFI).then(data => {
});
```
## sharing.on('sharingStateChange')
## sharing.on('sharingStateChange')
<sup>9+</sup>
on(type: 'sharingStateChange', callback: Callback
\<
boolean>): void
...
...
@@ -857,7 +857,7 @@ sharing.on('sharingStateChange', (data) => {
});
```
## sharing.off('sharingStateChange')
## sharing.off('sharingStateChange')
<sup>9+</sup>
off(type: 'sharingStateChange', callback?: Callback
\<
boolean>): void
...
...
@@ -891,7 +891,7 @@ sharing.off('sharingStateChange', (data) => {
});
```
## sharing.on('interfaceSharingStateChange')
## sharing.on('interfaceSharingStateChange')
<sup>9+</sup>
on(type: 'interfaceSharingStateChange', callback: Callback
\<
{ type: SharingIfaceType, iface: string, state:
SharingIfaceState }>): void
...
...
@@ -926,7 +926,7 @@ sharing.on('interfaceSharingStateChange', (data) => {
});
```
## sharing.off('interfaceSharingStateChange')
## sharing.off('interfaceSharingStateChange')
<sup>9+</sup>
off(type: 'interfaceSharingStateChange', callback?: Callback
\<
{ type: SharingIfaceType, iface: string, state:
SharingIfaceState }>): void
...
...
@@ -961,7 +961,7 @@ sharing.off('interfaceSharingStateChange', (data) => {
});
```
## sharing.on('sharingUpstreamChange')
## sharing.on('sharingUpstreamChange')
<sup>9+</sup>
on(type: 'sharingUpstreamChange', callback: Callback
\<
NetHandle>): void
...
...
@@ -995,7 +995,7 @@ sharing.on('sharingUpstreamChange', (data) => {
});
```
## sharing.off('sharingUpstreamChange')
## sharing.off('sharingUpstreamChange')
<sup>9+</sup>
off(type: 'sharingUpstreamChange', callback?: Callback
\<
NetHandle>): void
...
...
@@ -1029,7 +1029,7 @@ sharing.off('sharingUpstreamChange', (data) => {
});
```
## SharingIfaceState
## SharingIfaceState
<sup>9+</sup>
网络共享状态。
...
...
@@ -1043,7 +1043,7 @@ sharing.off('sharingUpstreamChange', (data) => {
| SHARING_NIC_CAN_SERVER | 2 | 可提供网络共享。 |
| SHARING_NIC_ERROR | 3 | 网络共享错误。 |
## SharingIfaceType
## SharingIfaceType
<sup>9+</sup>
网络共享类型。
...
...
zh-cn/application-dev/reference/apis/js-apis-socket.md
浏览文件 @
5ed0c454
...
...
@@ -12,7 +12,7 @@
import
socket
from
'
@ohos.net.socket
'
;
```
## socket.constructUDPSocketInstance
## socket.constructUDPSocketInstance
<sup>9+</sup>
constructUDPSocketInstance(): UDPSocket
...
...
@@ -32,19 +32,16 @@ constructUDPSocketInstance(): UDPSocket
let
udp
=
socket
.
constructUDPSocketInstance
();
```
## UDPSocket
## UDPSocket
<sup>9+</sup>
UDPSocket连接。在调用UDPSocket的方法前,需要先通过
[
socket.constructUDPSocketInstance
](
#socketconstructudpsocketinstance
)
创建UDPSocket对象。
### bind
### bind
<sup>9+</sup>
bind(address: NetAddress, callback: AsyncCallback
\<
void
\>
): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
...
...
@@ -67,7 +64,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
```
js
let
udp
=
socket
.
constructUDPSocketInstance
();
udp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
udp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -76,15 +73,12 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
})
```
### bind
### bind
<sup>9+</sup>
bind(address: NetAddress): Promise
\<
void
\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
...
...
@@ -120,7 +114,7 @@ promise.then(() => {
});
```
### send
### send
<sup>9+</sup>
send(options: UDPSendOptions, callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -166,7 +160,7 @@ udp.send({
})
```
### send
### send
<sup>9+</sup>
send(options: UDPSendOptions): Promise
\<
void
\>
...
...
@@ -216,7 +210,7 @@ promise.then(() => {
});
```
### close
### close
<sup>9+</sup>
close(callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -245,7 +239,7 @@ udp.close(err => {
})
```
### close
### close
<sup>9+</sup>
close(): Promise
\<
void
\>
...
...
@@ -273,7 +267,7 @@ promise.then(() => {
});
```
### getState
### getState
<sup>9+</sup>
getState(callback: AsyncCallback
\<
SocketStateBase
\>
): void
...
...
@@ -318,7 +312,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
})
```
### getState
### getState
<sup>9+</sup>
getState(): Promise
\<
SocketStateBase
\>
...
...
@@ -357,7 +351,7 @@ promise.then(err => {
});
```
### setExtraOptions
### setExtraOptions
<sup>9+</sup>
setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -410,7 +404,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
})
```
### setExtraOptions
### setExtraOptions
<sup>9+</sup>
setExtraOptions(options: UDPExtraOptions): Promise
\<
void
\>
...
...
@@ -466,7 +460,7 @@ promise.then(() => {
});
```
### on('message')
### on('message')
<sup>9+</sup>
on(type: 'message', callback: Callback
\<
{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}
\>
): void
...
...
@@ -497,7 +491,7 @@ udp.on('message', value => {
});
```
### off('message')
### off('message')
<sup>9+</sup>
off(type: 'message', callback?: Callback
\<
{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}
\>
): void
...
...
@@ -535,7 +529,7 @@ udp.off('message', callback);
udp
.
off
(
'
message
'
);
```
### on('listening' | 'close')
### on('listening' | 'close')
<sup>9+</sup>
on(type: 'listening' | 'close', callback: Callback
\<
void
\>
): void
...
...
@@ -562,7 +556,7 @@ udp.on('close', () => {
});
```
### off('listening' | 'close')
### off('listening' | 'close')
<sup>9+</sup>
off(type: 'listening' | 'close', callback?: Callback
\<
void
\>
): void
...
...
@@ -600,7 +594,7 @@ udp.off('close', callback2);
udp
.
off
(
'
close
'
);
```
### on('error')
### on('error')
<sup>9+</sup>
on(type: 'error', callback: ErrorCallback): void
...
...
@@ -624,7 +618,7 @@ udp.on('error', err => {
});
```
### off('error')
### off('error')
<sup>9+</sup>
off(type: 'error', callback?: ErrorCallback): void
...
...
@@ -655,7 +649,7 @@ udp.off('error', callback);
udp
.
off
(
'
error
'
);
```
## NetAddress
## NetAddress
<sup>9+</sup>
目标地址信息。
...
...
@@ -667,7 +661,7 @@ udp.off('error');
| port | number | 否 | 端口号 ,范围0~65535。如果不指定系统随机分配端口。 |
| family | number | 否 | 网络协议类型,可选类型:
<br
/>
- 1:IPv4
<br
/>
- 2:IPv6
<br
/>
默认为1。 |
## UDPSendOptions
## UDPSendOptions
<sup>9+</sup>
UDPSocket发送参数。
...
...
@@ -678,7 +672,7 @@ UDPSocket发送参数。
| data | string
\|
ArrayBuffer
<sup>
7+
</sup>
| 是 | 发送的数据。 |
| address |
[
NetAddress
](
#netaddress
)
| 是 | 目标地址信息。 |
## UDPExtraOptions
## UDPExtraOptions
<sup>9+</sup>
UDPSocket连接的其他属性。
...
...
@@ -692,7 +686,7 @@ UDPSocket连接的其他属性。
| reuseAddress | boolean | 否 | 是否重用地址。默认为false。 |
| socketTimeout | number | 否 | 套接字超时时间,单位毫秒(ms)。 |
## SocketStateBase
## SocketStateBase
<sup>9+</sup>
Socket的状态信息。
...
...
@@ -704,7 +698,7 @@ Socket的状态信息。
| isClose | boolean | 是 | 是否关闭。 |
| isConnected | boolean | 是 | 是否连接。 |
## SocketRemoteInfo
## SocketRemoteInfo
<sup>9+</sup>
Socket的连接信息。
...
...
@@ -723,7 +717,7 @@ UDP 其余错误码映射形式为:2301000 + Linux内核错误码。
错误码的详细介绍参见
[
Socket错误码
](
../errorcodes/errorcode-net-socket.md
)
## socket.constructTCPSocketInstance
## socket.constructTCPSocketInstance
<sup>9+</sup>
constructTCPSocketInstance(): TCPSocket
...
...
@@ -743,19 +737,16 @@ constructTCPSocketInstance(): TCPSocket
let
tcp
=
socket
.
constructTCPSocketInstance
();
```
## TCPSocket
## TCPSocket
<sup>9+</sup>
TCPSocket连接。在调用TCPSocket的方法前,需要先通过
[
socket.constructTCPSocketInstance
](
#socketconstructtcpsocketinstance
)
创建TCPSocket对象。
### bind
### bind
<sup>9+</sup>
bind(address: NetAddress, callback: AsyncCallback
\<
void
\>
): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
...
...
@@ -778,7 +769,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
```
js
let
tcp
=
socket
.
constructTCPSocketInstance
();
tcp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
tcp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -787,15 +778,12 @@ tcp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
})
```
### bind
### bind
<sup>9+</sup>
bind(address: NetAddress): Promise
\<
void
\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
...
...
@@ -831,7 +819,7 @@ promise.then(() => {
});
```
### connect
### connect
<sup>9+</sup>
connect(options: TCPConnectOptions, callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -871,7 +859,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
})
```
### connect
### connect
<sup>9+</sup>
connect(options: TCPConnectOptions): Promise
\<
void
\>
...
...
@@ -912,7 +900,7 @@ promise.then(() => {
});
```
### send
### send
<sup>9+</sup>
send(options: TCPSendOptions, callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -958,7 +946,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
})
```
### send
### send
<sup>9+</sup>
send(options: TCPSendOptions): Promise
\<
void
\>
...
...
@@ -1010,7 +998,7 @@ promise1.then(() => {
});
```
### close
### close
<sup>9+</sup>
close(callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -1045,7 +1033,7 @@ tcp.close(err => {
})
```
### close
### close
<sup>9+</sup>
close(): Promise
\<
void
\>
...
...
@@ -1079,7 +1067,7 @@ promise.then(() => {
});
```
### getRemoteAddress
### getRemoteAddress
<sup>9+</sup>
getRemoteAddress(callback: AsyncCallback
\<
NetAddress
\>
): void
...
...
@@ -1120,7 +1108,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
});
```
### getRemoteAddress
### getRemoteAddress
<sup>9+</sup>
getRemoteAddress(): Promise
\<
NetAddress
\>
...
...
@@ -1163,7 +1151,7 @@ promise1.then(() => {
});
```
### getState
### getState
<sup>9+</sup>
getState(callback: AsyncCallback
\<
SocketStateBase
\>
): void
...
...
@@ -1204,7 +1192,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
});
```
### getState
### getState
<sup>9+</sup>
getState(): Promise
\<
SocketStateBase
\>
...
...
@@ -1247,7 +1235,7 @@ promise.then(() => {
});
```
### setExtraOptions
### setExtraOptions
<sup>9+</sup>
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback
\<
void
\>
): void
...
...
@@ -1299,7 +1287,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
});
```
### setExtraOptions
### setExtraOptions
<sup>9+</sup>
setExtraOptions(options: TCPExtraOptions): Promise
\<
void
\>
...
...
@@ -1358,7 +1346,7 @@ promise.then(() => {
});
```
### on('message')
### on('message')
<sup>9+</sup>
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}
\>
): void
...
...
@@ -1389,7 +1377,7 @@ tcp.on('message', value => {
});
```
### off('message')
### off('message')
<sup>9+</sup>
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}
\>
): void
...
...
@@ -1427,7 +1415,7 @@ tcp.off('message', callback);
tcp
.
off
(
'
message
'
);
```
### on('connect' | 'close')
### on('connect' | 'close')
<sup>9+</sup>
on(type: 'connect' | 'close', callback: Callback
\<
void
\>
): void
...
...
@@ -1454,7 +1442,7 @@ tcp.on('close', () => {
});
```
### off('connect' | 'close')
### off('connect' | 'close')
<sup>9+</sup>
off(type: 'connect' | 'close', callback?: Callback
\<
void
\>
): void
...
...
@@ -1492,7 +1480,7 @@ tcp.off('close', callback2);
tcp
.
off
(
'
close
'
);
```
### on('error')
### on('error')
<sup>9+</sup>
on(type: 'error', callback: ErrorCallback): void
...
...
@@ -1516,7 +1504,7 @@ tcp.on('error', err => {
});
```
### off('error')
### off('error')
<sup>9+</sup>
off(type: 'error', callback?: ErrorCallback): void
...
...
@@ -1547,7 +1535,7 @@ tcp.off('error', callback);
tcp
.
off
(
'
error
'
);
```
## TCPConnectOptions
## TCPConnectOptions
<sup>9+</sup>
TCPSocket连接的参数。
...
...
@@ -1558,7 +1546,7 @@ TCPSocket连接的参数。
| address |
[
NetAddress
](
#netaddress
)
| 是 | 绑定的地址以及端口。 |
| timeout | number | 否 | 超时时间,单位毫秒(ms)。 |
## TCPSendOptions
## TCPSendOptions
<sup>9+</sup>
TCPSocket发送请求的参数。
...
...
@@ -1569,7 +1557,7 @@ TCPSocket发送请求的参数。
| data | string
\|
ArrayBuffer
<sup>
7+
</sup>
| 是 | 发送的数据。 |
| encoding | string | 否 | 字符编码(UTF-8,UTF-16BE,UTF-16LE,UTF-16,US-AECII,ISO-8859-1),默认为UTF-8。 |
## TCPExtraOptions
## TCPExtraOptions
<sup>9+</sup>
TCPSocket连接的其他属性。
...
...
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
浏览文件 @
5ed0c454
...
...
@@ -67,7 +67,7 @@ ws.connect(defaultIpAddress, (err, value) => {
});
```
## webSocket.createWebSocket
## webSocket.createWebSocket
<sup>6+</sup>
createWebSocket(): WebSocket
...
...
@@ -87,11 +87,11 @@ createWebSocket(): WebSocket
let
ws
=
webSocket
.
createWebSocket
();
```
## WebSocket
## WebSocket
<sup>6+</sup>
在调用WebSocket的方法前,需要先通过
[
webSocket.createWebSocket
](
#websocketcreatewebsocket
)
创建一个WebSocket。
### connect
### connect
<sup>6+</sup>
connect(url: string, callback: AsyncCallback
\<
boolean
\>
): void
...
...
@@ -132,7 +132,7 @@ ws.connect(url, (err, value) => {
});
```
### connect
### connect
<sup>6+</sup>
connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback
\<
boolean
\>
): void
...
...
@@ -179,7 +179,7 @@ ws.connect(url, {
});
```
### connect
### connect
<sup>6+</sup>
connect(url: string, options?: WebSocketRequestOptions): Promise
\<
boolean
\>
...
...
@@ -225,7 +225,7 @@ promise.then((value) => {
});
```
### send
### send
<sup>6+</sup>
send(data: string | ArrayBuffer, callback: AsyncCallback
\<
boolean
\>
): void
...
...
@@ -265,7 +265,7 @@ ws.connect(url, (err, value) => {
});
```
### send
### send
<sup>6+</sup>
send(data: string | ArrayBuffer): Promise
\<
boolean
\>
...
...
@@ -309,7 +309,7 @@ ws.connect(url, (err, value) => {
});
```
### close
### close
<sup>6+</sup>
close(callback: AsyncCallback
\<
boolean
\>
): void
...
...
@@ -345,7 +345,7 @@ ws.close((err, value) => {
});
```
### close
### close
<sup>6+</sup>
close(options: WebSocketCloseOptions, callback: AsyncCallback
\<
boolean
\>
): void
...
...
@@ -385,7 +385,7 @@ ws.close({
});
```
### close
### close
<sup>6+</sup>
close(options?: WebSocketCloseOptions): Promise
\<
boolean
\>
...
...
@@ -429,7 +429,7 @@ promise.then((value) => {
});
```
### on('open')
### on('open')
<sup>6+</sup>
on(type: 'open', callback: AsyncCallback
\<
Object
\>
): void
...
...
@@ -453,7 +453,7 @@ ws.on('open', (err, value) => {
});
```
### off('open')
### off('open')
<sup>6+</sup>
off(type: 'open', callback?: AsyncCallback
\<
Object
\>
): void
...
...
@@ -483,7 +483,7 @@ ws.on('open', callback1);
ws
.
off
(
'
open
'
,
callback1
);
```
### on('message')
### on('message')
<sup>6+</sup>
on(type: 'message', callback: AsyncCallback
\<
string | ArrayBuffer
\>
): void
...
...
@@ -510,7 +510,7 @@ ws.on('message', (err, value) => {
});
```
### off('message')
### off('message')
<sup>6+</sup>
off(type: 'message', callback?: AsyncCallback
\<
string | ArrayBuffer
\>
): void
...
...
@@ -536,7 +536,7 @@ let ws = webSocket.createWebSocket();
ws
.
off
(
'
message
'
);
```
### on('close')
### on('close')
<sup>6+</sup>
on(type: 'close', callback: AsyncCallback
\<
{ code: number, reason: string }
\>
): void
...
...
@@ -560,7 +560,7 @@ ws.on('close', (err, value) => {
});
```
### off('close')
### off('close')
<sup>6+</sup>
off(type: 'close', callback?: AsyncCallback
\<
{ code: number, reason: string }
\>
): void
...
...
@@ -585,7 +585,7 @@ let ws = webSocket.createWebSocket();
ws
.
off
(
'
close
'
);
```
### on('error')
### on('error')
<sup>6+</sup>
on(type: 'error', callback: ErrorCallback): void
...
...
@@ -609,7 +609,7 @@ ws.on('error', (err) => {
});
```
### off('error')
### off('error')
<sup>6+</sup>
off(type: 'error', callback?: ErrorCallback): void
...
...
@@ -668,4 +668,3 @@ ws.off('error');
| 1002 | 协议错误 |
| 1003 | 无法处理的数据类型 |
| 1004~1015 | 保留值 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录