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

!23711 修改net相关md文件

Merge pull request !23711 from 徐杰/feature_ex_beta2
...@@ -28,7 +28,7 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac ...@@ -28,7 +28,7 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------ | | -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
| iface | string | 是 | 网络接口名 | | iface | string | 是 | 网络接口名 |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | 是 | 要设置的网络接口配置信息 | | ic | [InterfaceConfiguration](#interfaceconfiguration9) | 是 | 要设置的网络接口配置信息 |
| callback | AsyncCallback\<void> | 是 | 回调函数,成功无返回,失败返回对应错误码。 | | callback | AsyncCallback\<void> | 是 | 回调函数,成功无返回,失败返回对应错误码。 |
**错误码:** **错误码:**
...@@ -55,12 +55,7 @@ ethernet.setIfaceConfig("eth0", { ...@@ -55,12 +55,7 @@ ethernet.setIfaceConfig("eth0", {
route: "192.168.xx.xxx", route: "192.168.xx.xxx",
gateway: "192.168.xx.xxx", gateway: "192.168.xx.xxx",
netMask: "255.255.255.0", netMask: "255.255.255.0",
dnsServers: "1.1.1.1", dnsServers: "1.1.1.1"
httpProxy: {
host: "180.89.xx.xx",
port: 8080,
exclusionList: {"example.com","192.168.0.1"}
}
}, (error) => { }, (error) => {
if (error) { if (error) {
console.log("setIfaceConfig callback error = " + JSON.stringify(error)); console.log("setIfaceConfig callback error = " + JSON.stringify(error));
...@@ -87,7 +82,7 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void> ...@@ -87,7 +82,7 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------- | ---- | ------------------------ | | ------ | ------------------------------------------------- | ---- | ------------------------ |
| iface | string | 是 | 接口名 | | iface | string | 是 | 接口名 |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | 是 | 要设置的网络接口配置信息 | | ic | [InterfaceConfiguration](#interfaceconfiguration9) | 是 | 要设置的网络接口配置信息 |
**返回值:** **返回值:**
...@@ -119,12 +114,7 @@ ethernet.setIfaceConfig("eth0", { ...@@ -119,12 +114,7 @@ ethernet.setIfaceConfig("eth0", {
route: "192.168.xx.xxx", route: "192.168.xx.xxx",
gateway: "192.168.xx.xxx", gateway: "192.168.xx.xxx",
netMask: "255.255.255.0", netMask: "255.255.255.0",
dnsServers: "1.1.1.1", dnsServers: "1.1.1.1"
httpProxy: {
host: "180.89.xx.xx",
port: 8080,
exclusionList: {"example.com","192.168.0.1"}
}
}).then(() => { }).then(() => {
console.log("setIfaceConfig promise ok "); console.log("setIfaceConfig promise ok ");
}).catch(error => { }).catch(error => {
......
...@@ -708,7 +708,7 @@ getTrafficStatsByIface(ifaceInfo: IfaceInfo, callback: AsyncCallback\<NetStatsIn ...@@ -708,7 +708,7 @@ getTrafficStatsByIface(ifaceInfo: IfaceInfo, callback: AsyncCallback\<NetStatsIn
endTime: 16859485670 endTime: 16859485670
} }
statistics.getTrafficStatsByIface(ifaceInfo), (error, statsInfo) => { statistics.getTrafficStatsByIface((ifaceInfo), (error, statsInfo) => {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log("getTrafficStatsByIface bytes of received = " + JSON.stringify(statsInfo.rxBytes)); console.log("getTrafficStatsByIface bytes of received = " + JSON.stringify(statsInfo.rxBytes));
console.log("getTrafficStatsByIface bytes of sent = " + JSON.stringify(statsInfo.txBytes)); console.log("getTrafficStatsByIface bytes of sent = " + JSON.stringify(statsInfo.txBytes));
...@@ -761,7 +761,7 @@ getTrafficStatsByIface(ifaceInfo: IfaceInfo): Promise\<NetStatsInfo>; ...@@ -761,7 +761,7 @@ getTrafficStatsByIface(ifaceInfo: IfaceInfo): Promise\<NetStatsInfo>;
endTime: 16859485670 endTime: 16859485670
} }
statistics.getTrafficStatsByIface().then(function (statsInfo) { statistics.getTrafficStatsByIface(ifaceInfo).then(function (statsInfo) {
console.log("getTrafficStatsByIface bytes of received = " + JSON.stringify(statsInfo.rxBytes)); console.log("getTrafficStatsByIface bytes of received = " + JSON.stringify(statsInfo.rxBytes));
console.log("getTrafficStatsByIface bytes of sent = " + JSON.stringify(statsInfo.txBytes)); console.log("getTrafficStatsByIface bytes of sent = " + JSON.stringify(statsInfo.txBytes));
console.log("getTrafficStatsByIface packets of received = " + JSON.stringify(statsInfo.rxPackets)); console.log("getTrafficStatsByIface packets of received = " + JSON.stringify(statsInfo.rxPackets));
...@@ -814,7 +814,7 @@ getTrafficStatsByUid(uidInfo: UidInfo, callback: AsyncCallback\<NetStatsInfo>): ...@@ -814,7 +814,7 @@ getTrafficStatsByUid(uidInfo: UidInfo, callback: AsyncCallback\<NetStatsInfo>):
uid: 20010037 uid: 20010037
} }
statistics.getTrafficStatsByUid(uidInfo), (error, statsInfo) => { statistics.getTrafficStatsByUid((uidInfo), (error, statsInfo) => {
console.log(JSON.stringify(error)) console.log(JSON.stringify(error))
console.log("getTrafficStatsByUid bytes of received = " + JSON.stringify(statsInfo.rxBytes)); console.log("getTrafficStatsByUid bytes of received = " + JSON.stringify(statsInfo.rxBytes));
console.log("getTrafficStatsByUid bytes of sent = " + JSON.stringify(statsInfo.txBytes)); console.log("getTrafficStatsByUid bytes of sent = " + JSON.stringify(statsInfo.txBytes));
......
...@@ -43,16 +43,16 @@ createVpnConnection(context: AbilityContext): VpnConnection ...@@ -43,16 +43,16 @@ createVpnConnection(context: AbilityContext): VpnConnection
Stage模型示例: Stage模型示例:
```ts ```ts
// 获取context // 获取context
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
globalThis.context = this.context; globalThis.context = this.context;
} }
} }
let context = globalThis.context; let context = globalThis.context;
VpnConnection = vpn.createVpnConnection(context); let VpnConnection = vpn.createVpnConnection(context);
console.info("vpn onInit: " + JSON.stringify(VpnConnection)); console.info("vpn onInit: " + JSON.stringify(VpnConnection));
``` ```
## VpnConnection ## VpnConnection
...@@ -96,6 +96,14 @@ setUp(config: VpnConfig, callback: AsyncCallback\<number\>): void ...@@ -96,6 +96,14 @@ setUp(config: VpnConfig, callback: AsyncCallback\<number\>): void
**示例:** **示例:**
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
let config = { let config = {
addresses: [{ addresses: [{
address: { address: {
...@@ -160,6 +168,14 @@ setUp(config: VpnConfig): Promise\<number\> ...@@ -160,6 +168,14 @@ setUp(config: VpnConfig): Promise\<number\>
**示例:** **示例:**
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
let config = { let config = {
addresses: [{ addresses: [{
address: { address: {
...@@ -220,6 +236,14 @@ protect(socketFd: number, callback: AsyncCallback\<void\>): void ...@@ -220,6 +236,14 @@ protect(socketFd: number, callback: AsyncCallback\<void\>): void
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
var tcp = socket.constructTCPSocketInstance(); var tcp = socket.constructTCPSocketInstance();
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -283,6 +307,14 @@ protect(socketFd: number): Promise\<void\> ...@@ -283,6 +307,14 @@ protect(socketFd: number): Promise\<void\>
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
var tcp = socket.constructTCPSocketInstance(); var tcp = socket.constructTCPSocketInstance();
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -339,6 +371,13 @@ destroy(callback: AsyncCallback\<void\>): void ...@@ -339,6 +371,13 @@ destroy(callback: AsyncCallback\<void\>): void
**示例:** **示例:**
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
VpnConnection.destroy((error) => { VpnConnection.destroy((error) => {
console.info(JSON.stringify(error)); console.info(JSON.stringify(error));
}) })
...@@ -376,6 +415,13 @@ destroy(): Promise\<void\> ...@@ -376,6 +415,13 @@ destroy(): Promise\<void\>
**示例:** **示例:**
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
globalThis.context = this.context;
}
}
let VpnConnection = vpn.createVpnConnection(globalThis.context);
VpnConnection.destroy().then(() => { VpnConnection.destroy().then(() => {
console.info("destroy success.") console.info("destroy success.")
}).catch(err => { }).catch(err => {
......
...@@ -1262,7 +1262,7 @@ getSocketFd(callback: AsyncCallback\<number\>): void ...@@ -1262,7 +1262,7 @@ getSocketFd(callback: AsyncCallback\<number\>): void
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0 let tunnelfd = 0
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -1302,7 +1302,7 @@ getSocketFd(): Promise\<number\> ...@@ -1302,7 +1302,7 @@ getSocketFd(): Promise\<number\>
```js ```js
import socket from "@ohos.net.socket"; import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0 let tunnelfd = 0
tcp.bind({ tcp.bind({
address: "0.0.0.0", address: "0.0.0.0",
...@@ -2936,6 +2936,7 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket ...@@ -2936,6 +2936,7 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = ''; let messageView = '';
tls.on('message', value => { tls.on('message', value => {
...@@ -2970,6 +2971,7 @@ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: Soc ...@@ -2970,6 +2971,7 @@ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: Soc
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = ''; let messageView = '';
let callback = value => { let callback = value => {
...@@ -3003,6 +3005,7 @@ on(type: 'connect' | 'close', callback: Callback\<void\>): void ...@@ -3003,6 +3005,7 @@ on(type: 'connect' | 'close', callback: Callback\<void\>): void
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
tls.on('connect', () => { tls.on('connect', () => {
console.log("on connect success") console.log("on connect success")
...@@ -3033,6 +3036,7 @@ off(type: 'connect' | 'close', callback?: Callback\<void\>): void ...@@ -3033,6 +3036,7 @@ off(type: 'connect' | 'close', callback?: Callback\<void\>): void
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let callback1 = () => { let callback1 = () => {
console.log("on connect success"); console.log("on connect success");
...@@ -3067,6 +3071,7 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -3067,6 +3071,7 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
tls.on('error', err => { tls.on('error', err => {
console.log("on error, err:" + JSON.stringify(err)) console.log("on error, err:" + JSON.stringify(err))
...@@ -3094,6 +3099,7 @@ off(type: 'error', callback?: ErrorCallback): void ...@@ -3094,6 +3099,7 @@ off(type: 'error', callback?: ErrorCallback): void
**示例:** **示例:**
```js ```js
import socket from '@ohos.net.socket';
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let callback = err => { let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册