提交 930f64c5 编写于 作者: Y Yangys

Add Tls on off

Signed-off-by: NYangys <yangyousheng@huawei.com>
Change-Id: I1fa48dc117a740598270eed958e361e1f13f42db
上级 3a5ba5f8
...@@ -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,43 +87,42 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -87,43 +87,42 @@ 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',
...@@ -138,7 +137,6 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -138,7 +137,6 @@ UDP与TCP流程大体类似,下面以TCP为例:
return; return;
} }
console.log('connect success'); console.log('connect success');
// 发送数据 // 发送数据
tcp.send({ tcp.send({
data: 'Hello, server!' data: 'Hello, server!'
...@@ -150,18 +148,17 @@ UDP与TCP流程大体类似,下面以TCP为例: ...@@ -150,18 +148,17 @@ UDP与TCP流程大体类似,下面以TCP为例:
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进行加密数据传输
...@@ -206,7 +203,7 @@ tlsTwoWay.on('close', () => { ...@@ -206,7 +203,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;
...@@ -278,7 +275,7 @@ tlsTwoWay.on('close', () => { ...@@ -278,7 +275,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;
......
...@@ -469,7 +469,7 @@ httpRequest.once('headersReceive', (header) => { ...@@ -469,7 +469,7 @@ httpRequest.once('headersReceive', (header) => {
| 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) | 否 | 使用协议。默认值由系统自动指定。 |
......
...@@ -416,7 +416,7 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo ...@@ -416,7 +416,7 @@ 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));
}); });
``` ```
......
...@@ -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,16 @@ setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void ...@@ -42,18 +42,16 @@ 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); this.callBack(error);
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 +84,8 @@ setBackgroundPolicy(isAllowed: boolean): Promise\<void> ...@@ -86,9 +84,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))
}) })
``` ```
...@@ -194,8 +191,8 @@ setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void> ...@@ -194,8 +191,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); console.log(JSON.stringify(error))
}); });
``` ```
...@@ -238,9 +235,8 @@ setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>; ...@@ -238,9 +235,8 @@ 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))
}) })
``` ```
...@@ -509,8 +505,8 @@ let param = { ...@@ -509,8 +505,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 +559,8 @@ let param = { ...@@ -563,9 +559,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 +595,8 @@ restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void ...@@ -600,8 +595,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,9 +636,8 @@ restoreAllPolicies(iccid: string): Promise\<void>; ...@@ -641,9 +636,8 @@ 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))
}) })
``` ```
...@@ -724,7 +718,6 @@ isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>; ...@@ -724,7 +718,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))
} }
...@@ -766,7 +759,6 @@ isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): ...@@ -766,7 +759,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 +810,6 @@ policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then( ...@@ -818,7 +810,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 +846,8 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\ ...@@ -855,8 +846,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,9 +890,8 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>; ...@@ -899,9 +890,8 @@ 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))
}) })
``` ```
...@@ -1080,8 +1070,8 @@ resetPolicies(iccid: string, callback: AsyncCallback\<void>): void ...@@ -1080,8 +1070,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,9 +1114,8 @@ policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function (error, d ...@@ -1124,9 +1114,8 @@ 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))
}) })
``` ```
...@@ -1252,8 +1241,8 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\< ...@@ -1252,8 +1241,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,9 +1285,8 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>; ...@@ -1296,9 +1285,8 @@ 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))
}) })
``` ```
...@@ -1393,7 +1381,7 @@ on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUid ...@@ -1393,7 +1381,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 +1406,7 @@ on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule ...@@ -1418,7 +1406,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 +1431,7 @@ on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void ...@@ -1443,7 +1431,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 +1456,7 @@ on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): v ...@@ -1468,7 +1456,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 +1481,7 @@ on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void ...@@ -1493,7 +1481,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
...@@ -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
...@@ -733,6 +739,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -733,6 +739,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
...@@ -770,6 +779,9 @@ bind(address: NetAddress): Promise\<void\> ...@@ -770,6 +779,9 @@ bind(address: NetAddress): Promise\<void\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。 绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET **需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack **系统能力**:SystemCapability.Communication.NetStack
...@@ -1605,7 +1617,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -1605,7 +1617,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 +1660,7 @@ bind(address: NetAddress): Promise\<void\> ...@@ -1648,7 +1660,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 +1692,7 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void ...@@ -1680,7 +1692,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 +1732,7 @@ getState(): Promise\<SocketStateBase\> ...@@ -1720,7 +1732,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 +1772,7 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void ...@@ -1760,7 +1772,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 +1784,7 @@ tls.setExtraOptions({ ...@@ -1772,7 +1784,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 +1796,6 @@ tls.setExtraOptions({ ...@@ -1784,7 +1796,6 @@ tls.setExtraOptions({
} }
console.log('setExtraOptions success'); console.log('setExtraOptions success');
}); });
``` ```
### setExtraOptions<sup>9+</sup> ### setExtraOptions<sup>9+</sup>
...@@ -1818,7 +1829,7 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\> ...@@ -1818,7 +1829,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 +1840,7 @@ let promise = tls.setExtraOptions({ ...@@ -1829,7 +1840,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,
...@@ -1881,7 +1892,7 @@ connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void ...@@ -1881,7 +1892,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 +1923,7 @@ tlsTwoWay.connect(options, (err, data) => { ...@@ -1912,7 +1923,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 +1991,7 @@ connect(options: TLSConnectOptions): Promise\<void\> ...@@ -1980,7 +1991,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 +2023,7 @@ tlsTwoWay.connect(options).then(data => { ...@@ -2012,7 +2023,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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册