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

!23710 修改net相关md文件

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