未验证 提交 5d25b60b 编写于 作者: O openharmony_ci 提交者: Gitee

!17508 Add TLSSocket On Off

Merge pull request !17508 from Yangys/tls_onoff
...@@ -158,7 +158,6 @@ httpRequest.request2( ...@@ -158,7 +158,6 @@ httpRequest.request2(
httpRequest.destroy(); httpRequest.destroy();
} }
); );
``` ```
## 相关实例 ## 相关实例
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
6. 当不使用该网络时,可以调用该对象的unregister()方法,取消订阅。 6. 当不使用该网络时,可以调用该对象的unregister()方法,取消订阅。
```js ```js
// 引入包名 // 引入包名
import connection from '@ohos.net.connection' import connection from '@ohos.net.connection'
let netCap = { let netCap = {
...@@ -128,7 +128,7 @@ conn.unregister((err, data) => { ...@@ -128,7 +128,7 @@ conn.unregister((err, data) => {
2. 调用getAllNets方法,获取所有处于连接状态的网络列表。 2. 调用getAllNets方法,获取所有处于连接状态的网络列表。
```js ```js
// 引入包名 // 引入包名
import connection from '@ohos.net.connection' import connection from '@ohos.net.connection'
// 获取所有处于连接状态的网络列表 // 获取所有处于连接状态的网络列表
...@@ -154,7 +154,7 @@ connection.getAllNets((err, data) => { ...@@ -154,7 +154,7 @@ connection.getAllNets((err, data) => {
4. 调用getConnectionProperties方法,获取NetHandle对应网络的连接信息。 4. 调用getConnectionProperties方法,获取NetHandle对应网络的连接信息。
```js ```js
// 引入包名 // 引入包名
import connection from '@ohos.net.connection' import connection from '@ohos.net.connection'
// 调用getDefaultNet方法,获取默认的数据网络(NetHandle) // 调用getDefaultNet方法,获取默认的数据网络(NetHandle)
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
5. 用户态通过getIfaceConfig方法,来获取指定网口“eth0”的网络属性,未设置过的以太网络默认为DHCP模式,获取自动分配的网络属性。 5. 用户态通过getIfaceConfig方法,来获取指定网口“eth0”的网络属性,未设置过的以太网络默认为DHCP模式,获取自动分配的网络属性。
```js ```js
// 从@ohos.net.ethernet中导入ethernet命名空间 // 从@ohos.net.ethernet中导入ethernet命名空间
import ethernet from '@ohos.net.ethernet' import ethernet from '@ohos.net.ethernet'
// getAllActiveIfaces获取所有活动的网络设备名称 // getAllActiveIfaces获取所有活动的网络设备名称
...@@ -96,7 +96,7 @@ ethernet.getIfaceConfig("eth0", (error, data) => { ...@@ -96,7 +96,7 @@ ethernet.getIfaceConfig("eth0", (error, data) => {
6. 用户态通过getIfaceConfig方法,来获取指定网口“eth0”的静态网络属性。 6. 用户态通过getIfaceConfig方法,来获取指定网口“eth0”的静态网络属性。
```js ```js
// 从@ohos.net.ethernet中导入ethernet命名空间 // 从@ohos.net.ethernet中导入ethernet命名空间
import ethernet from '@ohos.net.ethernet' import ethernet from '@ohos.net.ethernet'
// getAllActiveIfaces获取所有活动的网络设备名称 // getAllActiveIfaces获取所有活动的网络设备名称
...@@ -158,13 +158,13 @@ ethernet.getIfaceConfig("eth0", (error, data) => { ...@@ -158,13 +158,13 @@ ethernet.getIfaceConfig("eth0", (error, data) => {
4. 调用该对象的off()方法,取消订阅interfaceStateChange事件。 4. 调用该对象的off()方法,取消订阅interfaceStateChange事件。
```js ```js
// 从@ohos.net.ethernet中导入ethernet命名空间 // 从@ohos.net.ethernet中导入ethernet命名空间
import ethernet from '@ohos.net.ethernet' import ethernet from '@ohos.net.ethernet'
// 订阅interfaceStateChange事件 // 订阅interfaceStateChange事件
ethernet.on('interfaceStateChange', ((data) => { ethernet.on('interfaceStateChange', (data) => {
console.log(JSON.stringify(data)); console.log(JSON.stringify(data));
})); });
// 取消事件订阅 // 取消事件订阅
ethernet.off('interfaceStateChange'); ethernet.off('interfaceStateChange');
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
4. 接收到共享状态开启的回调,开启共享成功。 4. 接收到共享状态开启的回调,开启共享成功。
```js ```js
// 从@ohos.net.sharing中导入sharing命名空间 // 从@ohos.net.sharing中导入sharing命名空间
import sharing from '@ohos.net.sharing' import sharing from '@ohos.net.sharing'
// 注册监听共享状态的改变 // 注册监听共享状态的改变
...@@ -85,7 +85,7 @@ sharing.startSharing(sharing.SharingIfaceType.SHARING_WIFI, (error) => { ...@@ -85,7 +85,7 @@ sharing.startSharing(sharing.SharingIfaceType.SHARING_WIFI, (error) => {
4. 接收到共享状态关闭的回调,停止共享成功。 4. 接收到共享状态关闭的回调,停止共享成功。
```js ```js
// 从@ohos.net.sharing中导入sharing命名空间 // 从@ohos.net.sharing中导入sharing命名空间
import sharing from '@ohos.net.sharing' import sharing from '@ohos.net.sharing'
// 注册监听共享状态的改变 // 注册监听共享状态的改变
...@@ -110,7 +110,7 @@ sharing.stopSharing(sharing.SharingIfaceType.SHARING_WIFI, (error) => { ...@@ -110,7 +110,7 @@ sharing.stopSharing(sharing.SharingIfaceType.SHARING_WIFI, (error) => {
4. 调用stopSharing方法,来停止指定类型共享,共享网络数据量清零。 4. 调用stopSharing方法,来停止指定类型共享,共享网络数据量清零。
```js ```js
// 从@ohos.net.sharing中导入sharing命名空间 // 从@ohos.net.sharing中导入sharing命名空间
import sharing from '@ohos.net.sharing' import sharing from '@ohos.net.sharing'
// 调用startSharing方法,来开启指定类型共享 // 调用startSharing方法,来开启指定类型共享
......
...@@ -87,81 +87,81 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -87,81 +87,81 @@ UDP与TCP流程大体类似,下面以TCP为例:
7. Socket连接使用完毕后,主动关闭。 7. Socket连接使用完毕后,主动关闭。
```js ```js
import socket from '@ohos.net.socket' import socket from '@ohos.net.socket'
// 创建一个TCPSocket连接,返回一个TCPSocket对象。 // 创建一个TCPSocket连接,返回一个TCPSocket对象。
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
// 订阅TCPSocket相关的订阅事件 // 订阅TCPSocket相关的订阅事件
tcp.on('message', value => { tcp.on('message', value => {
console.log("on message") console.log("on message")
let buffer = value.message let buffer = value.message
let dataView = new DataView(buffer) let dataView = new DataView(buffer)
let str = "" let str = ""
for (let i = 0;i < dataView.byteLength; ++i) { for (let i = 0; i < dataView.byteLength; ++i) {
str += String.fromCharCode(dataView.getUint8(i)) str += String.fromCharCode(dataView.getUint8(i))
} }
console.log("on connect received:" + str) console.log("on connect received:" + str)
}); });
tcp.on('connect', () => { tcp.on('connect', () => {
console.log("on connect") console.log("on connect")
}); });
tcp.on('close', () => { tcp.on('close', () => {
console.log("on close") console.log("on close")
}); });
// 绑定本地IP地址和端口。 // 绑定本地IP地址和端口。
let bindAddress = { let bindAddress = {
address: '192.168.xx.xx', address: '192.168.xx.xx',
port: 1234, // 绑定端口,如1234 port: 1234, // 绑定端口,如1234
family: 1 family: 1
}; };
tcp.bind(bindAddress, err => { tcp.bind(bindAddress, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
} }
console.log('bind success'); console.log('bind success');
// 连接到指定的IP地址和端口。 // 连接到指定的IP地址和端口。
let connectAddress = { let connectAddress = {
address: '192.168.xx.xx', address: '192.168.xx.xx',
port: 5678, // 连接端口,如5678 port: 5678, // 连接端口,如5678
family: 1 family: 1
}; };
tcp.connect({ tcp.connect({
address: connectAddress, timeout: 6000 address: connectAddress, timeout: 6000
}, err => { }, err => {
if (err) { if (err) {
console.log('connect fail'); console.log('connect fail');
return; return;
} }
console.log('connect success'); console.log('connect success');
// 发送数据 // 发送数据
tcp.send({ tcp.send({
data: 'Hello, server!' data: 'Hello, server!'
}, err => { }, err => {
if (err) { if (err) {
console.log('send fail'); console.log('send fail');
return; return;
} }
console.log('send success'); console.log('send success');
}) })
}); });
}); });
// 连接使用完毕后,主动关闭。取消相关事件的订阅。 // 连接使用完毕后,主动关闭。取消相关事件的订阅。
setTimeout(() => { setTimeout(() => {
tcp.close((err) => { tcp.close((err) => {
console.log('close socket.') console.log('close socket.')
}); });
tcp.off('message'); tcp.off('message');
tcp.off('connect'); tcp.off('connect');
tcp.off('close'); tcp.off('close');
}, 30 * 1000); }, 30 * 1000);
``` ```
## 应用通过TLS Socket进行加密数据传输 ## 应用通过TLS Socket进行加密数据传输
...@@ -184,7 +184,7 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -184,7 +184,7 @@ UDP与TCP流程大体类似,下面以TCP为例:
7. TLSSocket连接使用完毕后,主动关闭。 7. TLSSocket连接使用完毕后,主动关闭。
```js ```js
import socket from '@ohos.net.socket' import socket from '@ohos.net.socket'
// 创建一个(双向认证)TLS Socket连接,返回一个TLS Socket对象。 // 创建一个(双向认证)TLS Socket连接,返回一个TLS Socket对象。
let tlsTwoWay = socket.constructTLSSocketInstance(); let tlsTwoWay = socket.constructTLSSocketInstance();
...@@ -208,7 +208,7 @@ tlsTwoWay.on('close', () => { ...@@ -208,7 +208,7 @@ tlsTwoWay.on('close', () => {
}); });
// 绑定本地IP地址和端口。 // 绑定本地IP地址和端口。
tlsTwoWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { tlsTwoWay.bind({ address: '192.168.xxx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -280,7 +280,7 @@ tlsTwoWay.on('close', () => { ...@@ -280,7 +280,7 @@ tlsTwoWay.on('close', () => {
}); });
// 绑定本地IP地址和端口。 // 绑定本地IP地址和端口。
tlsOneWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { tlsOneWay.bind({ address: '192.168.xxx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
......
...@@ -37,49 +37,49 @@ WebSocket连接功能主要由webSocket模块提供。使用该功能需要申 ...@@ -37,49 +37,49 @@ WebSocket连接功能主要由webSocket模块提供。使用该功能需要申
5. 使用完WebSocket连接之后,主动断开连接。 5. 使用完WebSocket连接之后,主动断开连接。
```js ```js
import webSocket from '@ohos.net.webSocket'; import webSocket from '@ohos.net.webSocket';
var defaultIpAddress = "ws://"; var defaultIpAddress = "ws://";
let ws = webSocket.createWebSocket(); let ws = webSocket.createWebSocket();
ws.on('open', (err, value) => { ws.on('open', (err, value) => {
console.log("on open, status:" + JSON.stringify(value)); console.log("on open, status:" + JSON.stringify(value));
// 当收到on('open')事件时,可以通过send()方法与服务器进行通信 // 当收到on('open')事件时,可以通过send()方法与服务器进行通信
ws.send("Hello, server!", (err, value) => { ws.send("Hello, server!", (err, value) => {
if (!err) { if (!err) {
console.log("Message sent successfully"); console.log("Message sent successfully");
} else { } else {
console.log("Failed to send the message. Err:" + JSON.stringify(err)); console.log("Failed to send the message. Err:" + JSON.stringify(err));
} }
}); });
}); });
ws.on('message', (err, value) => { ws.on('message', (err, value) => {
console.log("on message, message:" + value); console.log("on message, message:" + value);
// 当收到服务器的`bye`消息时(此消息字段仅为示意,具体字段需要与服务器协商),主动断开连接 // 当收到服务器的`bye`消息时(此消息字段仅为示意,具体字段需要与服务器协商),主动断开连接
if (value === 'bye') { if (value === 'bye') {
ws.close((err, value) => { ws.close((err, value) => {
if (!err) { if (!err) {
console.log("Connection closed successfully"); console.log("Connection closed successfully");
} else { } else {
console.log("Failed to close the connection. Err: " + JSON.stringify(err)); console.log("Failed to close the connection. Err: " + JSON.stringify(err));
} }
}); });
} }
}); });
ws.on('close', (err, value) => { ws.on('close', (err, value) => {
console.log("on close, code is " + value.code + ", reason is " + value.reason); console.log("on close, code is " + value.code + ", reason is " + value.reason);
}); });
ws.on('error', (err) => { ws.on('error', (err) => {
console.log("on error, error:" + JSON.stringify(err)); console.log("on error, error:" + JSON.stringify(err));
}); });
ws.connect(defaultIpAddress, (err, value) => { ws.connect(defaultIpAddress, (err, value) => {
if (!err) { if (!err) {
console.log("Connected successfully"); console.log("Connected successfully");
} else { } else {
console.log("Connection failed. Err:" + JSON.stringify(err)); console.log("Connection failed. Err:" + JSON.stringify(err));
} }
}); });
``` ```
## 相关实例 ## 相关实例
......
...@@ -65,6 +65,9 @@ httpRequest.request( ...@@ -65,6 +65,9 @@ httpRequest.request(
); );
``` ```
> **说明:**
> console.info()输出的数据中包含换行符会导致数据出现截断现象。
## http.createHttp ## http.createHttp
createHttp(): HttpRequest createHttp(): HttpRequest
...@@ -98,7 +101,7 @@ request(url: string, callback: AsyncCallback\<HttpResponse\>):void ...@@ -98,7 +101,7 @@ request(url: string, callback: AsyncCallback\<HttpResponse\>):void
根据URL地址,发起HTTP网络请求,使用callback方式作为异步方法。 根据URL地址,发起HTTP网络请求,使用callback方式作为异步方法。
> **说明:** > **说明:**
> 此接口仅支持数据大小为5M以内的数据传输 > 此接口仅支持数据大小为5M以内的数据接收
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
...@@ -149,7 +152,7 @@ request(url: string, options: HttpRequestOptions, callback: AsyncCallback\<HttpR ...@@ -149,7 +152,7 @@ request(url: string, options: HttpRequestOptions, callback: AsyncCallback\<HttpR
根据URL地址和相关配置项,发起HTTP网络请求,使用callback方式作为异步方法。 根据URL地址和相关配置项,发起HTTP网络请求,使用callback方式作为异步方法。
> **说明:** > **说明:**
> 此接口仅支持数据大小为5M以内的数据传输 > 此接口仅支持数据大小为5M以内的数据接收
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
...@@ -235,7 +238,7 @@ request(url: string, options? : HttpRequestOptions): Promise\<HttpResponse\> ...@@ -235,7 +238,7 @@ request(url: string, options? : HttpRequestOptions): Promise\<HttpResponse\>
根据URL地址,发起HTTP网络请求,使用Promise方式作为异步方法。 根据URL地址,发起HTTP网络请求,使用Promise方式作为异步方法。
> **说明:** > **说明:**
> 此接口仅支持数据大小为5M以内的数据传输 > 此接口仅支持数据大小为5M以内的数据接收
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
...@@ -535,7 +538,7 @@ promise.then((data) => { ...@@ -535,7 +538,7 @@ promise.then((data) => {
}); });
``` ```
### on('headerReceive') ### on('headerReceive')<sup>(deprecated)</sup>
on(type: 'headerReceive', callback: AsyncCallback\<Object\>): void on(type: 'headerReceive', callback: AsyncCallback\<Object\>): void
...@@ -561,7 +564,7 @@ httpRequest.on('headerReceive', (data) => { ...@@ -561,7 +564,7 @@ httpRequest.on('headerReceive', (data) => {
}); });
``` ```
### off('headerReceive') ### off('headerReceive')<sup>(deprecated)</sup>
off(type: 'headerReceive', callback?: AsyncCallback\<Object\>): void off(type: 'headerReceive', callback?: AsyncCallback\<Object\>): void
...@@ -813,7 +816,7 @@ httpRequest.off('dataProgress'); ...@@ -813,7 +816,7 @@ httpRequest.off('dataProgress');
| usingCache<sup>9+</sup> | boolean | 否 | 是否使用缓存,默认为true。 | | usingCache<sup>9+</sup> | boolean | 否 | 是否使用缓存,默认为true。 |
| priority<sup>9+</sup> | number | 否 | 优先级,范围\[0,1000],默认是0。 | | priority<sup>9+</sup> | number | 否 | 优先级,范围\[0,1000],默认是0。 |
| header | Object | 否 | HTTP请求头字段。默认{'Content-Type': 'application/json'}。 | | header | Object | 否 | HTTP请求头字段。默认{'Content-Type': 'application/json'}。 |
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 | | readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。<br />设置为0表示不会出现超时情况。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 | | connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 | | usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 |
| usingProxy<sup>10+</sup> | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。<br />- 当usingProxy为布尔类型true时,使用默认网络代理。<br />- 当usingProxy为object类型时,使用指定网络代理。 | | usingProxy<sup>10+</sup> | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。<br />- 当usingProxy为布尔类型true时,使用默认网络代理。<br />- 当usingProxy为object类型时,使用指定网络代理。 |
......
...@@ -403,7 +403,7 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo ...@@ -403,7 +403,7 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- | | -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 | | type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 |
| callback | AsyncCallback\<{ iface: string, active: boolean }\> | 是 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) | | callback | Callback\<{ iface: string, active: boolean }\> | 是 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) |
**错误码:** **错误码:**
...@@ -416,8 +416,8 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo ...@@ -416,8 +416,8 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo
**示例:** **示例:**
```js ```js
ethernet.on('interfaceStateChange', (data) => { ethernet.on('interfaceStateChange', (data) => {
console.log('on interfaceSharingStateChange:' + JSON.stringify(data)); console.log('on interfaceSharingStateChange:' + JSON.stringify(data.iface) + JSON.stringify(data.active));
}); });
``` ```
...@@ -438,7 +438,7 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active: ...@@ -438,7 +438,7 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- | | -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 | | type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 |
| callback | AsyncCallback\<{ iface: string, active: boolean }> | 否 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) | | callback | Callback\<{ iface: string, active: boolean }> | 否 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) |
**错误码:** **错误码:**
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
import policy from '@ohos.net.policy' import policy from '@ohos.net.policy'
``` ```
## policy.setBackgroundPolicy ## policy.setBackgroundAllowed
setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void setBackgroundAllowed(isAllowed: boolean, callback: AsyncCallback\<void>): void
设置后台网络策略,使用callback方式作为异步方法。 设置后台网络策略,使用callback方式作为异步方法。
...@@ -42,18 +42,15 @@ setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void ...@@ -42,18 +42,15 @@ setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))), (error, data) => { policy.setBackgroundAllowed(Boolean(Number.parseInt(this.isBoolean)), (error) => {
this.callBack(error, data);
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) })
}
)
; ;
``` ```
## policy.setBackgroundPolicy ## policy.setBackgroundAllowed
setBackgroundPolicy(isAllowed: boolean): Promise\<void> setBackgroundAllowed(isAllowed: boolean): Promise\<void>
设置后台网络策略,使用Promise方式作为异步方法。 设置后台网络策略,使用Promise方式作为异步方法。
...@@ -86,9 +83,8 @@ setBackgroundPolicy(isAllowed: boolean): Promise\<void> ...@@ -86,9 +83,8 @@ setBackgroundPolicy(isAllowed: boolean): Promise\<void>
**示例:** **示例:**
```js ```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))).then(function (error, data) { policy.setBackgroundAllowed(Boolean(Number.parseInt(this.isBoolean))).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
...@@ -157,7 +153,6 @@ policy.isBackgroundAllowed().then(function (error, data) { ...@@ -157,7 +153,6 @@ policy.isBackgroundAllowed().then(function (error, data) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) console.log(JSON.stringify(data))
}) })
``` ```
## policy.setPolicyByUid ## policy.setPolicyByUid
...@@ -194,8 +189,8 @@ setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void> ...@@ -194,8 +189,8 @@ setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void>
let param = { let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy) uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
} }
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (error, data) => { policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (error) => {
this.callBack(error, data); this.callBack(error);
}); });
``` ```
...@@ -238,11 +233,9 @@ setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>; ...@@ -238,11 +233,9 @@ setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
let param = { let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy) uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
} }
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then(function (error, data) { policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.getPolicyByUid ## policy.getPolicyByUid
...@@ -319,7 +312,6 @@ policy.getPolicyByUid(Number.parseInt(this.firstParam)).then(function (error, da ...@@ -319,7 +312,6 @@ policy.getPolicyByUid(Number.parseInt(this.firstParam)).then(function (error, da
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) console.log(JSON.stringify(data))
}) })
``` ```
## policy.getUidsByPolicy ## policy.getUidsByPolicy
...@@ -396,7 +388,6 @@ policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function (error, d ...@@ -396,7 +388,6 @@ policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function (error, d
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) console.log(JSON.stringify(data))
}) })
``` ```
## policy.getNetQuotaPolicies ## policy.getNetQuotaPolicies
...@@ -509,8 +500,8 @@ let param = { ...@@ -509,8 +500,8 @@ let param = {
}; };
this.netQuotaPolicyList.push(param); this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList, (error, data) => { policy.setNetQuotaPolicies(this.netQuotaPolicyList, (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -563,9 +554,8 @@ let param = { ...@@ -563,9 +554,8 @@ let param = {
}; };
this.netQuotaPolicyList.push(param); this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList).then(function (error, data) { policy.setNetQuotaPolicies(this.netQuotaPolicyList).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
...@@ -600,8 +590,8 @@ restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void ...@@ -600,8 +590,8 @@ restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void
```js ```js
this.firstParam = iccid; this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam, (error, data) => { policy.restoreAllPolicies(this.firstParam, (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -641,11 +631,9 @@ restoreAllPolicies(iccid: string): Promise\<void>; ...@@ -641,11 +631,9 @@ restoreAllPolicies(iccid: string): Promise\<void>;
```js ```js
this.firstParam = iccid; this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam).then(function (error, data) { policy.restoreAllPolicies(this.firstParam).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.isUidNetAllowed ## policy.isUidNetAllowed
...@@ -679,7 +667,6 @@ isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolea ...@@ -679,7 +667,6 @@ isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolea
**示例:** **示例:**
```js ```js
let param = { let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
} }
...@@ -724,7 +711,6 @@ isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>; ...@@ -724,7 +711,6 @@ isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
**示例:** **示例:**
```js ```js
let param = { let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
} }
...@@ -732,7 +718,6 @@ policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt ...@@ -732,7 +718,6 @@ policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) console.log(JSON.stringify(data))
}) })
``` ```
## policy.isUidNetAllowed ## policy.isUidNetAllowed
...@@ -766,7 +751,6 @@ isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): ...@@ -766,7 +751,6 @@ isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>):
**示例:** **示例:**
```js ```js
let param = { let param = {
uid: Number.parseInt(this.firstParam), iface: this.secondParam uid: Number.parseInt(this.firstParam), iface: this.secondParam
} }
...@@ -818,7 +802,6 @@ policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then( ...@@ -818,7 +802,6 @@ policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then(
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data)) console.log(JSON.stringify(data))
}) })
``` ```
## policy.setDeviceIdleAllowList ## policy.setDeviceIdleAllowList
...@@ -855,8 +838,8 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\ ...@@ -855,8 +838,8 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\
let param = { let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
} }
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => { policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -899,11 +882,9 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>; ...@@ -899,11 +882,9 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
let param = { let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
} }
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function (error, data) { policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.getDeviceIdleAllowList ## policy.getDeviceIdleAllowList
...@@ -1080,8 +1061,8 @@ resetPolicies(iccid: string, callback: AsyncCallback\<void>): void ...@@ -1080,8 +1061,8 @@ resetPolicies(iccid: string, callback: AsyncCallback\<void>): void
```js ```js
this.firstParam = iccid this.firstParam = iccid
policy.resetPolicies(this.firstParam, (error, data) => { policy.resetPolicies(this.firstParam, (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -1124,11 +1105,9 @@ policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function (error, d ...@@ -1124,11 +1105,9 @@ policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function (error, d
}) })
this.firstParam = iccid this.firstParam = iccid
policy.resetPolicies(this.firstParam).then(function (error, data) { policy.resetPolicies(this.firstParam).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.updateRemindPolicy ## policy.updateRemindPolicy
...@@ -1166,8 +1145,8 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, ...@@ -1166,8 +1145,8 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType,
let param = { let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
} }
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (error, data) => { policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -1211,11 +1190,9 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): ...@@ -1211,11 +1190,9 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType):
let param = { let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
} }
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then(function (error, data) { policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.setPowerSaveAllowList ## policy.setPowerSaveAllowList
...@@ -1252,8 +1229,8 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\< ...@@ -1252,8 +1229,8 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\<
let param = { let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
} }
policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => { policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error) => {
this.callBack(error, data); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -1296,11 +1273,9 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>; ...@@ -1296,11 +1273,9 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>;
let param = { let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean)) uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
} }
policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function (error, data) { policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function (error) {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
}) })
``` ```
## policy.getPowerSaveAllowList ## policy.getPowerSaveAllowList
...@@ -1393,7 +1368,7 @@ on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUid ...@@ -1393,7 +1368,7 @@ on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUid
```js ```js
policy.on('netUidPolicyChange', (data) => { policy.on('netUidPolicyChange', (data) => {
this.log('on netUidPolicyChange' + JSON.stringify(data)); this.log('on netUidPolicyChange: ' + JSON.stringify(data));
}) })
``` ```
...@@ -1418,7 +1393,7 @@ on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule ...@@ -1418,7 +1393,7 @@ on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule
```js ```js
policy.on('netUidRuleChange', (data) => { policy.on('netUidRuleChange', (data) => {
this.log('on netUidRuleChange' + JSON.stringify(data)); this.log('on netUidRuleChange: ' + JSON.stringify(data));
}) })
``` ```
...@@ -1443,7 +1418,7 @@ on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void ...@@ -1443,7 +1418,7 @@ on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void
```js ```js
policy.on('netMeteredIfacesChange', (data) => { policy.on('netMeteredIfacesChange', (data) => {
this.log('on netMeteredIfacesChange' + JSON.stringify(data)); this.log('on netMeteredIfacesChange: ' + JSON.stringify(data));
}) })
``` ```
...@@ -1468,7 +1443,7 @@ on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): v ...@@ -1468,7 +1443,7 @@ on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): v
```js ```js
policy.on('netQuotaPolicyChange', (data) => { policy.on('netQuotaPolicyChange', (data) => {
this.log('on netQuotaPolicyChange' + JSON.stringify(data)); this.log('on netQuotaPolicyChange: ' + JSON.stringify(data));
}) })
``` ```
...@@ -1493,7 +1468,7 @@ on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void ...@@ -1493,7 +1468,7 @@ on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void
```js ```js
policy.on('netBackgroundPolicyChange', (data) => { policy.on('netBackgroundPolicyChange', (data) => {
this.log('on netBackgroundPolicyChange' + JSON.stringify(data)); this.log('on netBackgroundPolicyChange: ' + JSON.stringify(data));
}) })
``` ```
......
...@@ -42,6 +42,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -42,6 +42,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方式作为异步方法。 绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack **系统能力**:SystemCapability.Communication.NetStack
...@@ -64,7 +67,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -64,7 +67,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
```js ```js
let udp = socket.constructUDPSocketInstance(); 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) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -79,6 +82,9 @@ bind(address: NetAddress): Promise\<void\> ...@@ -79,6 +82,9 @@ bind(address: NetAddress): Promise\<void\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方式作为异步方法。 绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack **系统能力**:SystemCapability.Communication.NetStack
...@@ -106,7 +112,7 @@ bind(address: NetAddress): Promise\<void\> ...@@ -106,7 +112,7 @@ bind(address: NetAddress): Promise\<void\>
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.bind({address: '192.168.xx.xxx', port: 8080, family: 1}); let promise = udp.bind({ address: '192.168.xx.xxx', port: 8080, family: 1 });
promise.then(() => { promise.then(() => {
console.log('bind success'); console.log('bind success');
}).catch(err => { }).catch(err => {
...@@ -335,7 +341,7 @@ getState(): Promise\<SocketStateBase\> ...@@ -335,7 +341,7 @@ getState(): Promise\<SocketStateBase\>
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promise = udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 });
promise.then(err => { promise.then(err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
...@@ -382,7 +388,7 @@ setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void ...@@ -382,7 +388,7 @@ setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void
```js ```js
let udp = socket.constructUDPSocketInstance(); 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) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -440,7 +446,7 @@ setExtraOptions(options: UDPExtraOptions): Promise\<void\> ...@@ -440,7 +446,7 @@ setExtraOptions(options: UDPExtraOptions): Promise\<void\>
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promise = udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 });
promise.then(() => { promise.then(() => {
console.log('bind success'); console.log('bind success');
let promise1 = udp.setExtraOptions({ let promise1 = udp.setExtraOptions({
...@@ -480,7 +486,14 @@ on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: Socke ...@@ -480,7 +486,14 @@ on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: Socke
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.on('message', value => { udp.on('message', value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}); });
``` ```
...@@ -507,7 +520,14 @@ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: Soc ...@@ -507,7 +520,14 @@ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: Soc
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let callback = value => { let callback = value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
} }
udp.on('message', callback); udp.on('message', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 // 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
...@@ -733,6 +753,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -733,6 +753,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方法作为异步方法。 绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack **系统能力**:SystemCapability.Communication.NetStack
...@@ -755,7 +778,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -755,7 +778,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); 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) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -770,6 +793,9 @@ bind(address: NetAddress): Promise\<void\> ...@@ -770,6 +793,9 @@ bind(address: NetAddress): Promise\<void\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。 绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack **系统能力**:SystemCapability.Communication.NetStack
...@@ -797,7 +823,7 @@ bind(address: NetAddress): Promise\<void\> ...@@ -797,7 +823,7 @@ bind(address: NetAddress): Promise\<void\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promise = tcp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 });
promise.then(() => { promise.then(() => {
console.log('bind success'); console.log('bind success');
}).catch(err => { }).catch(err => {
...@@ -836,7 +862,7 @@ connect(options: TCPConnectOptions, callback: AsyncCallback\<void\>): void ...@@ -836,7 +862,7 @@ connect(options: TCPConnectOptions, callback: AsyncCallback\<void\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}, err => { tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 }, err => {
if (err) { if (err) {
console.log('connect fail'); console.log('connect fail');
return; return;
...@@ -878,7 +904,7 @@ connect(options: TCPConnectOptions): Promise\<void\> ...@@ -878,7 +904,7 @@ connect(options: TCPConnectOptions): Promise\<void\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}); let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 });
promise.then(() => { promise.then(() => {
console.log('connect success') console.log('connect success')
}).catch(err => { }).catch(err => {
...@@ -917,7 +943,7 @@ send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void ...@@ -917,7 +943,7 @@ send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}, () => { tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 }, () => {
console.log('connect success'); console.log('connect success');
tcp.send({ tcp.send({
data: 'Hello, server!' data: 'Hello, server!'
...@@ -968,7 +994,7 @@ send(options: TCPSendOptions): Promise\<void\> ...@@ -968,7 +994,7 @@ send(options: TCPSendOptions): Promise\<void\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise1 = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}); let promise1 = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 });
promise1.then(() => { promise1.then(() => {
console.log('connect success'); console.log('connect success');
let promise2 = tcp.send({ let promise2 = tcp.send({
...@@ -1082,7 +1108,7 @@ getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void ...@@ -1082,7 +1108,7 @@ getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}, () => { tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 }, () => {
console.log('connect success'); console.log('connect success');
tcp.getRemoteAddress((err, data) => { tcp.getRemoteAddress((err, data) => {
if (err) { if (err) {
...@@ -1123,7 +1149,7 @@ getRemoteAddress(): Promise\<NetAddress\> ...@@ -1123,7 +1149,7 @@ getRemoteAddress(): Promise\<NetAddress\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise1 = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}); let promise1 = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 });
promise1.then(() => { promise1.then(() => {
console.log('connect success'); console.log('connect success');
let promise2 = tcp.getRemoteAddress(); let promise2 = tcp.getRemoteAddress();
...@@ -1166,7 +1192,7 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void ...@@ -1166,7 +1192,7 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}, () => { let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 }, () => {
console.log('connect success'); console.log('connect success');
tcp.getState((err, data) => { tcp.getState((err, data) => {
if (err) { if (err) {
...@@ -1207,7 +1233,7 @@ getState(): Promise\<SocketStateBase\> ...@@ -1207,7 +1233,7 @@ getState(): Promise\<SocketStateBase\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}); let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 });
promise.then(() => { promise.then(() => {
console.log('connect success'); console.log('connect success');
let promise1 = tcp.getState(); let promise1 = tcp.getState();
...@@ -1252,13 +1278,13 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void ...@@ -1252,13 +1278,13 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}, () => { let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 }, () => {
console.log('connect success'); console.log('connect success');
tcp.setExtraOptions({ tcp.setExtraOptions({
keepAlive: true, keepAlive: true,
OOBInline: true, OOBInline: true,
TCPNoDelay: true, TCPNoDelay: true,
socketLinger: {on: true, linger: 10}, socketLinger: { on: true, linger: 10 },
receiveBufferSize: 1000, receiveBufferSize: 1000,
sendBufferSize: 1000, sendBufferSize: 1000,
reuseAddress: true, reuseAddress: true,
...@@ -1309,14 +1335,14 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\> ...@@ -1309,14 +1335,14 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\>
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({address: {address: '192.168.xx.xxx', port: xxxx, family: 1}, timeout: 6000}); let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, timeout: 6000 });
promise.then(() => { promise.then(() => {
console.log('connect success'); console.log('connect success');
let promise1 = tcp.setExtraOptions({ let promise1 = tcp.setExtraOptions({
keepAlive: true, keepAlive: true,
OOBInline: true, OOBInline: true,
TCPNoDelay: true, TCPNoDelay: true,
socketLinger: {on: true, linger: 10}, socketLinger: { on: true, linger: 10 },
receiveBufferSize: 1000, receiveBufferSize: 1000,
sendBufferSize: 1000, sendBufferSize: 1000,
reuseAddress: true, reuseAddress: true,
...@@ -1352,7 +1378,14 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket ...@@ -1352,7 +1378,14 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.on('message', value => { tcp.on('message', value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo) for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}); });
``` ```
...@@ -1379,7 +1412,14 @@ off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: Sock ...@@ -1379,7 +1412,14 @@ off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: Sock
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let callback = value => { let callback = value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
} }
tcp.on('message', callback); tcp.on('message', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 // 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
...@@ -1409,7 +1449,7 @@ let tcp = socket.constructTCPSocketInstance(); ...@@ -1409,7 +1449,7 @@ let tcp = socket.constructTCPSocketInstance();
tcp.on('connect', () => { tcp.on('connect', () => {
console.log("on connect success") console.log("on connect success")
}); });
tcp.on('close', data => { tcp.on('close', () => {
console.log("on close success") console.log("on close success")
}); });
``` ```
...@@ -1605,7 +1645,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -1605,7 +1645,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```js
tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1648,7 +1688,7 @@ bind(address: NetAddress): Promise\<void\> ...@@ -1648,7 +1688,7 @@ bind(address: NetAddress): Promise\<void\>
**示例:** **示例:**
```js ```js
let promise = tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promise = tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 });
promise.then(() => { promise.then(() => {
console.log('bind success'); console.log('bind success');
}).catch(err => { }).catch(err => {
...@@ -1680,7 +1720,7 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void ...@@ -1680,7 +1720,7 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void
**示例:** **示例:**
```js ```js
let promise = tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { let promise = tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1720,7 +1760,7 @@ getState(): Promise\<SocketStateBase\> ...@@ -1720,7 +1760,7 @@ getState(): Promise\<SocketStateBase\>
**示例:** **示例:**
```js ```js
let promiseBind = tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promiseBind = tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 });
promiseBind.then(() => { promiseBind.then(() => {
console.log('bind success'); console.log('bind success');
}).catch((err) => { }).catch((err) => {
...@@ -1760,7 +1800,7 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void ...@@ -1760,7 +1800,7 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```js
tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1772,7 +1812,7 @@ tls.setExtraOptions({ ...@@ -1772,7 +1812,7 @@ tls.setExtraOptions({
keepAlive: true, keepAlive: true,
OOBInline: true, OOBInline: true,
TCPNoDelay: true, TCPNoDelay: true,
socketLinger: {on: true, linger: 10}, socketLinger: { on: true, linger: 10 },
receiveBufferSize: 1000, receiveBufferSize: 1000,
sendBufferSize: 1000, sendBufferSize: 1000,
reuseAddress: true, reuseAddress: true,
...@@ -1784,7 +1824,6 @@ tls.setExtraOptions({ ...@@ -1784,7 +1824,6 @@ tls.setExtraOptions({
} }
console.log('setExtraOptions success'); console.log('setExtraOptions success');
}); });
``` ```
### setExtraOptions<sup>9+</sup> ### setExtraOptions<sup>9+</sup>
...@@ -1818,7 +1857,7 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\> ...@@ -1818,7 +1857,7 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\>
**示例:** **示例:**
```js ```js
tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { tls.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1829,7 +1868,7 @@ let promise = tls.setExtraOptions({ ...@@ -1829,7 +1868,7 @@ let promise = tls.setExtraOptions({
keepAlive: true, keepAlive: true,
OOBInline: true, OOBInline: true,
TCPNoDelay: true, TCPNoDelay: true,
socketLinger: {on: true, linger: 10}, socketLinger: { on: true, linger: 10 },
receiveBufferSize: 1000, receiveBufferSize: 1000,
sendBufferSize: 1000, sendBufferSize: 1000,
reuseAddress: true, reuseAddress: true,
...@@ -1842,6 +1881,191 @@ promise.then(() => { ...@@ -1842,6 +1881,191 @@ promise.then(() => {
}); });
``` ```
### on('message')
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void;
订阅TLSSocket连接的接收消息事件。使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | 是 | 订阅的事件类型。'message':接收消息事件。 |
| callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | 是 | 回调函数。message:接收到的消息;remoteInfo:socket连接信息。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
tls.on('message', value => {
for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
});
```
### off('message')
off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
取消订阅TLSSocket连接的接收消息事件。使用callback方式作为异步方法。
> **说明:**
> 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | 是 | 订阅的事件类型。'message':接收消息事件。 |
| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | 否 | 回调函数。message:接收到的消息;remoteInfo:socket连接信息。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
let callback = value => {
for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i]
let message = String.fromCharCode(messages);
let messageView = '';
messageView += item;
}
console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}
tls.on('message', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tls.off('message', callback);
```
### on('connect' | 'close')
on(type: 'connect' | 'close', callback: Callback\<void\>): void
订阅TLSSocket的连接事件或关闭事件。使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 订阅的事件类型。<br />- 'connect':连接事件。<br />- 'close':关闭事件。 |
| callback | Callback\<void\> | 是 | 回调函数。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
tls.on('connect', () => {
console.log("on connect success")
});
tls.on('close', () => {
console.log("on close success")
});
```
### off('connect' | 'close')
off(type: 'connect' | 'close', callback?: Callback\<void\>): void
取消订阅TLSSocket的连接事件或关闭事件。使用callback方式作为异步方法。
> **说明:**
> 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 订阅的事件类型。<br />- 'connect':连接事件。<br />- 'close':关闭事件。 |
| callback | Callback\<void\> | 否 | 回调函数。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
let callback1 = () => {
console.log("on connect success");
}
tls.on('connect', callback1);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tls.off('connect', callback1);
tls.off('connect');
let callback2 = () => {
console.log("on close success");
}
tls.on('close', callback2);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tls.off('close', callback2);
```
### on('error')
on(type: 'error', callback: ErrorCallback): void
订阅TLSSocket连接的error事件。使用callback方式作为异步方法。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | ------------------------------------ |
| type | string | 是 | 订阅的事件类型。'error':error事件。 |
| callback | ErrorCallback | 是 | 回调函数。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
tls.on('error', err => {
console.log("on error, err:" + JSON.stringify(err))
});
```
### off('error')
off(type: 'error', callback?: ErrorCallback): void
取消订阅TLSSocket连接的error事件。使用callback方式作为异步方法。
> **说明:**
> 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | ------------------------------------ |
| type | string | 是 | 订阅的事件类型。'error':error事件。 |
| callback | ErrorCallback | 否 | 回调函数。 |
**示例:**
```js
let tls = socket.constructTLSSocketInstance();
let callback = err => {
console.log("on error, err:" + JSON.stringify(err));
}
tls.on('error', callback);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tls.off('error', callback);
```
### connect<sup>9+</sup> ### connect<sup>9+</sup>
connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void
...@@ -1881,7 +2105,7 @@ connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void ...@@ -1881,7 +2105,7 @@ connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void
```js ```js
let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication
tlsTwoWay.bind({address: '192.168.xxx.xxx', port: 8080, family: 1}, err => { tlsTwoWay.bind({ address: '192.168.xxx.xxx', port: 8080, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1912,7 +2136,7 @@ tlsTwoWay.connect(options, (err, data) => { ...@@ -1912,7 +2136,7 @@ tlsTwoWay.connect(options, (err, data) => {
}); });
let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication
tlsOneWay.bind({address: '192.168.xxx.xxx', port: 8080, family: 1}, err => { tlsOneWay.bind({ address: '192.168.xxx.xxx', port: 8080, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -1980,7 +2204,7 @@ connect(options: TLSConnectOptions): Promise\<void\> ...@@ -1980,7 +2204,7 @@ connect(options: TLSConnectOptions): Promise\<void\>
```js ```js
let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication
tlsTwoWay.bind({address: '192.168.xxx.xxx', port: 8080, family: 1}, err => { tlsTwoWay.bind({ address: '192.168.xxx.xxx', port: 8080, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -2012,7 +2236,7 @@ tlsTwoWay.connect(options).then(data => { ...@@ -2012,7 +2236,7 @@ tlsTwoWay.connect(options).then(data => {
}); });
let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication
tlsOneWay.bind({address: '192.168.xxx.xxx', port: 8080, family: 1}, err => { tlsOneWay.bind({ address: '192.168.xxx.xxx', port: 8080, family: 1 }, err => {
if (err) { if (err) {
console.log('bind fail'); console.log('bind fail');
return; return;
...@@ -2572,7 +2796,7 @@ close(): Promise\<void\> ...@@ -2572,7 +2796,7 @@ close(): Promise\<void\>
```js ```js
tls.close().then(() => { tls.close().then(() => {
console.log("close success"); console.log("close success");
}).catch(err => { }).catch((err) => {
console.error(err); console.error(err);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册