diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md b/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md index a40b423ad211ffb8ab7e75be25ba563740ce567a..7d9fc61be1811d0976b0747fce52701cc107206e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md @@ -28,7 +28,7 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------- | ---- | ------------------------------------------ | | iface | string | 是 | 网络接口名 | -| ic | [InterfaceConfiguration](#interfaceconfiguration) | 是 | 要设置的网络接口配置信息 | +| ic | [InterfaceConfiguration](#interfaceconfiguration9) | 是 | 要设置的网络接口配置信息 | | callback | AsyncCallback\ | 是 | 回调函数,成功无返回,失败返回对应错误码。 | **错误码:** @@ -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\ | 参数名 | 类型 | 必填 | 说明 | | ------ | ------------------------------------------------- | ---- | ------------------------ | | 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 => { diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md b/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md index 210ae339b766efc56b3418cc86449cfec2f20d1e..f6b148d6041b02964cd872c15ee21c7a00be06d4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md @@ -708,7 +708,7 @@ getTrafficStatsByIface(ifaceInfo: IfaceInfo, callback: AsyncCallback\ { + 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\; 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\): 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)); diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-vpn.md b/zh-cn/application-dev/reference/apis/js-apis-net-vpn.md index 2d7b20c3ef4447d585df1539741496e77ac23b02..4a0cb7fc9b815fba4d1c88fa8d7a169c69963f4e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-vpn.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-vpn.md @@ -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\): 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\ **示例:** ```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 ```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\ ```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 **示例:** ```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\ **示例:** ```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 => { diff --git a/zh-cn/application-dev/reference/apis/js-apis-socket.md b/zh-cn/application-dev/reference/apis/js-apis-socket.md index 3d738d0c54fabed536f959595ce3369d3e8b2543..fd826c5fb640e8469ee7168a1201bba7aedaadde 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-socket.md +++ b/zh-cn/application-dev/reference/apis/js-apis-socket.md @@ -1262,7 +1262,7 @@ getSocketFd(callback: AsyncCallback\): 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\ ```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 **示例:** ```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 **示例:** ```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));