diff --git a/en/application-dev/connectivity/net-mdns.md b/en/application-dev/connectivity/net-mdns.md index 16aa29609d0826388b244a7daebbcb1f849ed27e..de7982a5c03908a70e4005bdc5fbea3584c435f5 100644 --- a/en/application-dev/connectivity/net-mdns.md +++ b/en/application-dev/connectivity/net-mdns.md @@ -94,7 +94,7 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) { 1. Connect the device to the Wi-Fi network. 2. Import the **mdns** namespace from **@ohos.net.mdns**. -3. Create a **DiscoveryService** object, which is used to discover mDNS services of the specified type. +3. Creates a **DiscoveryService** object, which is used to discover mDNS services of the specified type. 4. Subscribe to mDNS service discovery status changes. 5. Enable discovery of mDNS services on the LAN. 6. Stop searching for mDNS services on the LAN. @@ -116,20 +116,6 @@ class EntryAbility extends UIAbility { } let context = globalThis.context; -// Create a LocalService object. -let localServiceInfo = { - serviceType: "_print._tcp", - serviceName: "servicename", - port: 5555, - host: { - address: "10.14.**.***", - }, - serviceAttribute: [{ - key: "111", - value: [1] - }] -} - // Create a DiscoveryService object, which is used to discover mDNS services of the specified type. let serviceType = "_print._tcp"; let discoveryService = mdns.createDiscoveryService(context, serviceType); diff --git a/en/application-dev/internationalization/i18n-guidelines.md b/en/application-dev/internationalization/i18n-guidelines.md index e78bdb6437b26b8a30ee23f9fdec380087297b33..f2393be5fb12c8011d267f0df295acfaacaec607 100644 --- a/en/application-dev/internationalization/i18n-guidelines.md +++ b/en/application-dev/internationalization/i18n-guidelines.md @@ -610,8 +610,10 @@ Call [Transliterator](../reference/apis/js-apis-i18n.md#transliterator9) APIs to Call **transform** to obtain the transliterated string. ```js - let transliterator = I18n.Transliterator.getInstance("Any-Latn"); // Any-Latn means to convert any text to Latn text. + let transliterator = I18n.Transliterator.getInstance("Any-Latin"); // Any-Latin means to convert any text to Latin text. let transformText = transliterator.transform ("Hello"); // transformText = "nǐ hǎo" + let transliterator2 = I18n.Transliterator.getInstance("Latin-ASCII"); // Latin-ASCII means to convert Latin text to ASCII text. + transformText = transliterator2.transform(transformText); // transformText = "ni hao" ``` ## Obtaining the Character Type diff --git a/en/application-dev/napi/Readme-EN.md b/en/application-dev/napi/Readme-EN.md index 0a94576a94274b066059ff37b07816db1e964294..ad566d55f740fd7ada74fe22b95e0f1824271c2d 100644 --- a/en/application-dev/napi/Readme-EN.md +++ b/en/application-dev/napi/Readme-EN.md @@ -1,17 +1,11 @@ # Native APIs - [Using Native APIs in Application Projects](napi-guidelines.md) -- Graphics - - [Drawing Development](drawing-guidelines.md) - - [NativeBuffer Development](native-buffer-guidelines.md) - - [NativeImage Development](native-image-guidelines.md) - - [NativeVsync Development](native-vsync-guidelines.md) - - [Native Window Development](native-window-guidelines.md) -- Resource Management - - [Raw File Development](rawfile-guidelines.md) -- AI - - [Using MindSpore Lite for Model Inference](mindspore-lite-guidelines.md) - - [Using MindSpore Lite for Offline Model Conversion and Inference](mindspore-lite-offline-model-guidelines.md) - - [Connecting the Neural Network Runtime to an AI Inference Framework](neural-network-runtime-guidelines.md) -- Memory Development +- [Drawing Development](drawing-guidelines.md) +- [Raw File Development](rawfile-guidelines.md) +- [Native Window Development](native-window-guidelines.md) +- [Using MindSpore Lite for Model Inference](mindspore-lite-guidelines.md) +- [Using MindSpore Lite for Offline Model Conversion and Inference](mindspore-lite-offline-model-guidelines.md) +- [Connecting the Neural Network Runtime to an AI Inference Framework](neural-network-runtime-guidelines.md) - [Purgeable Memory Development](purgeable-memory-guidelines.md) +- [USB DDK Development](usb-ddk-guidelines.md) \ No newline at end of file diff --git a/en/application-dev/napi/usb-ddk-guidelines.md b/en/application-dev/napi/usb-ddk-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..708a82dc905ce78b9f3823269c2bef392d595046 --- /dev/null +++ b/en/application-dev/napi/usb-ddk-guidelines.md @@ -0,0 +1,79 @@ +# USB DDK Development + +## When to Use + +USB Driver Development Kit (USB DDK) is a tool kit provided by OpenHarmony to help you develop USB device drivers for your applications based on the user mode. It provides a series of device access APIs, which implement functions such as opening and closing USB interfaces, performing non-isochronous and isochronous data transfer, and implementing control transfer and interrupt transfer over USB pipes, etc. + +## Available APIs + +| Name| Description| +| -------- | -------- | +| OH_Usb_Init(void) | Initializes the DDK.| +| OH_Usb_Release(void) | Releases the DDK.| +| OH_Usb_GetDeviceDescriptor(uint64_t deviceId, struct UsbDeviceDescriptor *desc) | Obtains the device descriptor.| +| OH_Usb_GetConfigDescriptor(uint64_t deviceId, uint8_t configIndex, struct UsbDdkConfigDescriptor **const config) | Obtains the configuration descriptor. To avoid memory leakage, use **OH_Usb_FreeConfigDescriptor()** to release a descriptor after use.| +| OH_Usb_FreeConfigDescriptor(const struct UsbDdkConfigDescriptor *const config) | Releases a configuration descriptor. To avoid memory leakage, release a descriptor after use.| +| OH_Usb_ClaimInterface(uint64_t deviceId, uint8_t interfaceIndex, uint64_t *interfaceHandle) | Declares a USB interface.| +| OH_Usb_ReleaseInterface(uint64_t interfaceHandle) | Releases a USB interface.| +| OH_Usb_SendPipeRequest(const struct UsbRequestPipe *pipe, UsbDeviceMemMap *devMmap) | Sends a pipe request. This API works in a synchronous manner. It applies to interrupt transfer and bulk transfer.| +| OH_Usb_CreateDeviceMemMap(uint64_t deviceId, size_t size, UsbDeviceMemMap **devMmap) | Creates a buffer. To avoid memory leakage, use **OH_Usb_DestroyDeviceMemMap()** to destroy a buffer after use.| +| OH_Usb_DestroyDeviceMemMap(UsbDeviceMemMap *devMmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.| + +For details about the APIs, see [USB DDK](../reference/native-apis/_usb_ddk.md). + +## How to Develop + +To develop a USB driver using the USB DDK in OpenHarmony, perform the following steps: + +1. Obtain the device descriptor. Initialize the DDK by calling **OH_Usb_Init** of **usb_ddk_api.h**, and obtain the device descriptor by calling **OH_Usb_GetDeviceDescriptor**. + + ```c++ + // Initialize the USB DDK. + OH_Usb_Init(); + struct UsbDeviceDescriptor devDesc; + uint64_t deviceId = 0; + // Obtain the device descriptor. + OH_Usb_GetDeviceDescriptor(deviceId, &devDesc); + ``` + +2. Obtain the configuration descriptor, and declare the USB interface. Obtain the configuration descriptor **config** by calling **OH_Usb_GetConfigDescriptor** of **usb_ddk_api.h**, and declare the USB interface by calling **OH_Usb_ClaimInterface**. + + ```c++ + struct UsbDdkConfigDescriptor *config = nullptr; + // Obtain the configuration descriptor. + OH_Usb_GetConfigDescriptor(deviceId, 1, &config); + // Obtain the index of the target USB interface based on the configuration descriptor. + uint8_t interfaceIndex = 0; + // Declare the USB interface. + uint64_t interfaceHandle = 0; + OH_Usb_ClaimInterface(deviceId, interfaceIndex, &interfaceHandle); + // Release the configuration descriptor. + OH_Usb_FreeConfigDescriptor(config); + ``` + +3. Create a device memory map, and send a request. Create the device memory map **devMmap** by calling **OH_Usb_CreateDeviceMemMap** of **usb_ddk_api.h**, and send a request by calling **OH_Usb_SendPipeRequest**. + + ```c++ + struct UsbDeviceMemMap *devMmap = nullptr; + // Create a buffer for storing data. + size_t bufferLen = 10; + OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMmap); + struct UsbRequestPipe pipe; + pipe.interfaceHandle = interfaceHandle; + // Obtain the target endpoint based on the configuration descriptor. + pipe.endpoint = 128; + pipe.timeout = UINT32_MAX; + // Send a request. + OH_Usb_SendPipeRequest(&pipe, devMmap); + ``` + +4. Release resources. After all requests are processed and before the application exits, destroy the buffer by calling **OH_Usb_DestroyDeviceMemMap** of **usb_ddk_api.h** to release resources. Release the USB interface by calling **OH_Usb_ReleaseInterface**. Release the USB DDK by calling **OH_Usb_Release**. + + ```c++ + // Destroy the buffer. + OH_Usb_DestroyDeviceMemMap(devMmap); + // Release the USB interface. + OH_Usb_ReleaseInterface(interfaceHandle); + // Release the USB DDK. + OH_Usb_Release(); + ``` diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 9c225026165d18d24c17bbae3f3ded66cc4c5d83..5c5432408a5664cf88ea9b4779f66acde8c51e37 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -221,7 +221,7 @@ - Resource Management - [@ohos.i18n (Internationalization)](js-apis-i18n.md) - [@ohos.intl (Internationalization)](js-apis-intl.md) - - [@ohos.resourceManager (Resource Manager)](js-apis-resource-manager.md) + - [@ohos.resourceManager (Resource Management)](js-apis-resource-manager.md) - Background Task - [@ohos.distributedMissionManager (Distributed Mission Management)](js-apis-distributedMissionManager.md) @@ -291,6 +291,7 @@ - [@ohos.net.mdns (mDNS Management)](js-apis-net-mdns.md) - [@ohos.net.sharing (Network Sharing)](js-apis-net-sharing.md) - [@ohos.net.socket (Socket Connection)](js-apis-socket.md) + - [@ohos.net.statistics (Traffic Management)](js-apis-net-statistics.md) - [@ohos.net.webSocket (WebSocket Connection)](js-apis-webSocket.md) - [@ohos.request (Upload and Download)](js-apis-request.md) @@ -368,7 +369,6 @@ - [@ohos.multimodalInput.shortKey (Shortcut Key)](js-apis-shortKey.md) - [@ohos.power (System Power Management)](js-apis-power.md) - [@ohos.runningLock (Runninglock)](js-apis-runninglock.md) - - [@ohos.resourceschedule.deviceStandby (Device Standby)](js-apis-resourceschedule-deviceStandby.md) - [@ohos.sensor (Sensor)](js-apis-sensor.md) - [@ohos.settings (Data Item Settings)](js-apis-settings.md) - [@ohos.stationary (Device Status Awareness Framework)](js-apis-stationary.md) diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index f7c52787326fe5429c6911e1e9500b48b0e0f615..a839c6b0b1fcc9d5af4d59d6537a6afec637b0a0 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -1750,6 +1750,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | +| 8300999 | Unknown error code. | **Example** @@ -1795,6 +1796,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r | 8300001 | Invalid parameter value. | | 8300002 | Operation failed. Cannot connect to service. | | 8300003 | System internal error. | +| 8300999 | Unknown error code. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index 06001e5f9dc363239d97258b99e6c186d0d21722..85a9a234ec13c4f740f2ea8dae644333fcd7584e 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -2060,7 +2060,7 @@ Checks whether the input character is an uppercase letter. static getType(char: string): string -Obtains the type of the input character string. +Obtains the category value of the input character string. **System capability**: SystemCapability.Global.I18n @@ -2074,14 +2074,49 @@ Obtains the type of the input character string. | Type | Description | | ------ | ----------- | -| string | Type of the input character.| +| string | Category value of the input character.| + +The following table lists only the general category values. For more details, see the Unicode Standard. + +| Name| Value| Description| +| ---- | -------- | ---------- | +| U_UNASSIGNED | U_UNASSIGNED | Non-category for unassigned and non-character code points.| +| U_GENERAL_OTHER_TYPES | U_GENERAL_OTHER_TYPES | Same as **U_UNASSIGNED**.| +| U_UPPERCASE_LETTER | U_UPPERCASE_LETTER | Uppercase letter.| +| U_LOWERCASE_LETTER | U_LOWERCASE_LETTER | Lowercase letter. | +| U_TITLECASE_LETTER | U_TITLECASE_LETTER | Title case letter.| +| U_MODIFIER_LETTER | U_MODIFIER_LETTER | Modifier letter.| +| U_OTHER_LETTER | U_OTHER_LETTER | Letters other than the uppercase letter, lowercase letter, title case letter, and modifier letter.| +| U_NON_SPACING_MARK | U_NON_SPACING_MARK | Non-spacing mark, such as the accent symbol **'** and the variable symbol **#**.| +| U_ENCLOSING_MARK | U_ENCLOSING_MARK | Enclosing mark, for example, a circle or a box.| +| U_COMBINING_SPACING_MARK | U_COMBINING_SPACING_MARK | Spacing mark, for example, the vowel symbol **[]**.| +| U_DECIMAL_DIGIT_NUMBER | U_DECIMAL_DIGIT_NUMBER | Decimal number.| +| U_LETTER_NUMBER | U_LETTER_NUMBER | Letter and number (including Roman numeral).| +| U_OTHER_NUMBER | U_OTHER_NUMBER | Other numbers, which are used as encryption symbols, marker symbols, or non-Arabic numerals, such as **@**, **#**, **(1)**, and **①**.| +| U_SPACE_SEPARATOR | U_SPACE_SEPARATOR | Space separator, for example, a space character, uninterrupted space character, or space character with a fixed width.| +| U_LINE_SEPARATOR | U_LINE_SEPARATOR | Line separator.| +| U_PARAGRAPH_SEPARATOR | U_PARAGRAPH_SEPARATOR | Paragraph separator.| +| U_CONTROL_CHAR | U_CONTROL_CHAR | Control character.| +| U_FORMAT_CHAR | U_FORMAT_CHAR | Format character.| +| U_PRIVATE_USE_CHAR | U_PRIVATE_USE_CHAR | Privately used character, for example, a company logo.| +| U_SURROGATE | U_SURROGATE | Surrogate, which is used to represent supplementary characters in UTF-16.| +| U_DASH_PUNCTUATION | U_DASH_PUNCTUATION | Dash punctuation.| +| U_START_PUNCTUATION | U_START_PUNCTUATION | Start punctuation, for example, the left parenthesis.| +| U_END_PUNCTUATION | U_END_PUNCTUATION | End punctuation, for example, the right parenthesis.| +| U_INITIAL_PUNCTUATION | U_INITIAL_PUNCTUATION | Initial punctuation, for example, the left double quotation mark or left single quotation mark.| +| U_FINAL_PUNCTUATION | U_FINAL_PUNCTUATION | Final punctuation, for example, the right double quotation mark or right single quotation mark.| +| U_CONNECTOR_PUNCTUATION | U_CONNECTOR_PUNCTUATION | Connector punctuation.| +| U_OTHER_PUNCTUATION | U_OTHER_PUNCTUATION | Other punctuations.| +| U_MATH_SYMBOL | U_MATH_SYMBOL | Mathematical symbol.| +| U_CURRENCY_SYMBOL | U_CURRENCY_SYMBOL | Currency symbol.| +| U_MODIFIER_SYMBOL | U_MODIFIER_SYMBOL | Modifier symbol.| +| U_OTHER_SYMBOL | U_OTHER_SYMBOL | Other symbols.| **Example** ```js let type = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER" ``` - ## I18NUtil9+ @@ -2368,6 +2403,8 @@ Represents the list of languages or countries/regions sorted by **SystemLocaleMa Represents the type of time zone city items. +**System API**: This is a system API. + **System capability**: SystemCapability.Global.I18n | Name | Type | Mandatory | Description | diff --git a/en/application-dev/reference/apis/js-apis-net-ethernet.md b/en/application-dev/reference/apis/js-apis-net-ethernet.md index 9195179a8dd054e5f9c5c76ded0b79fb7bb5b431..21fdb44e402a4a0cb4a6f39d883522ab84513217 100644 --- a/en/application-dev/reference/apis/js-apis-net-ethernet.md +++ b/en/application-dev/reference/apis/js-apis-net-ethernet.md @@ -1,6 +1,6 @@ # # @ohos.net.ethernet (Ethernet Connection Management) -The **ethernet** module provides wired network capabilities, which allow users to set the IP address, subnet mask, gateway, and Domain Name System (DNS) server of a wired network. +The **ethernet** module provides wired network capabilities, which allow users to set the IP address, subnet mask, gateway, and Domain Name System (DNS) server, and HTTP proxy of a wired network. > **NOTE** > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -55,7 +55,12 @@ ethernet.setIfaceConfig("eth0", { route: "192.168.xx.xxx", gateway: "192.168.xx.xxx", 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) => { if (error) { console.log("setIfaceConfig callback error = " + JSON.stringify(error)); @@ -114,7 +119,12 @@ ethernet.setIfaceConfig("eth0", { route: "192.168.xx.xxx", gateway: "192.168.xx.xxx", 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(() => { console.log("setIfaceConfig promise ok "); }).catch(error => { @@ -476,6 +486,7 @@ Defines the network configuration for the Ethernet connection. | gateway | string | Yes| Gateway of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.| | netMask | string | Yes| Subnet mask of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.| | dnsServers | string | Yes| DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).| +| httpProxy10+ | [HttpProxy](js-apis-net-connection.md#httpproxy) | No| HTTP proxy of the Ethernet connection. By default, no proxy is configured.| ## IPSetMode9+ diff --git a/en/application-dev/reference/apis/js-apis-net-statistics.md b/en/application-dev/reference/apis/js-apis-net-statistics.md new file mode 100644 index 0000000000000000000000000000000000000000..480104dfd176a744d78e8e67844e060a9b4ea7da --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-net-statistics.md @@ -0,0 +1,925 @@ +# @ohos.net.statistics (Traffic Management) + +The **statistics** module provides APIs to query real-time or historical data traffic by the specified network interface card (NIC) or user ID (UID). + +> **NOTE** +> +> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```js +import statistics from '@ohos.net.statistics' +``` + +## statistics.getIfaceRxBytes10+ + +getIfaceRxBytes(nic: string, callback: AsyncCallback\): void; + +Obtains the real-time downlink data traffic of the specified NIC. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| nic | string | Yes | NIC name. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time downlink data traffic of the NIC in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + + +**Example** + +```js + statistics.getIfaceRxBytes("wlan0", (error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getIfaceRxBytes10+ + +getIfaceRxBytes(nic: string): Promise\; + +Obtains the real-time downlink data traffic of the specified NIC. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| nic | string | Yes | NIC name. | + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time downlink data traffic of the NIC in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getIfaceRxBytes("wlan0").then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getIfaceTxBytes10+ + +getIfaceTxBytes(nic: string, callback: AsyncCallback\): void; + +Obtains the real-time uplink data traffic of the specified NIC. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| nic | string | Yes | NIC name. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time uplink data traffic of the NIC in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getIfaceTxBytes("wlan0", (error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getIfaceTxBytes10+ + +getIfaceTxBytes(nic: string): Promise\; + +Obtains the real-time uplink data traffic of the specified NIC. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| nic | string | Yes | NIC name. | + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time uplink data traffic of the NIC in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getIfaceTxBytes("wlan0").then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getCellularRxBytes10+ + +getCellularRxBytes(callback: AsyncCallback\): void; + +Obtains the real-time downlink data traffic of a cellular network. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time downlink data traffic of the cellular network in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getCellularRxBytes((error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getCellularRxBytes10+ + +getCellularRxBytes(): Promise\; + +Obtains the real-time downlink data traffic of a cellular network. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time downlink data traffic of the cellular network in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getCellularRxBytes().then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getCellularTxBytes10+ + +getCellularTxBytes(callback: AsyncCallback\): void; + +Obtains the real-time uplink data traffic of a cellular network. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time uplink data traffic of the cellular network in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getCellularTxBytes((error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getCellularTxBytes10+ + +getCellularTxBytes(): Promise\; + +Obtains the real-time uplink data traffic of a cellular network. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time uplink data traffic of the cellular network in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | +| 2103012 | Get iface name failed. | + +**Example** + +```js + statistics.getCellularTxBytes().then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getAllRxBytes10+ + +getAllRxBytes(callback: AsyncCallback\): void; + +Obtains the real-time downlink data traffic of all NICs. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time downlink data traffic of all NICs in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getAllRxBytes((error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getAllRxBytes10+ + +getAllRxBytes(): Promise\; + +Obtains the real-time downlink data traffic of all NICs. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time downlink data traffic of all NICs in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getCellularRxBytes().then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getAllTxBytes10+ + +getAllTxBytes(callback: AsyncCallback\): void; + +Obtains the real-time uplink data traffic of all NICs. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time uplink data traffic of all NICs in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getAllTxBytes((error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getAllTxBytes10+ + +getAllTxBytes(): Promise\; + +Obtains the real-time uplink data traffic of all NICs. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time uplink data traffic of all NICs in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getAllTxBytes().then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getUidRxBytes10+ + +getUidRxBytes(uid: number, callback: AsyncCallback\): void; + +Obtains the real-time downlink data traffic of the specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uid | number | Yes | Application UID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time downlink data traffic of the application in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getUidRxBytes(20010038, (error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getUidRxBytes10+ + +getUidRxBytes(uid: number): Promise\; + +Obtains the real-time downlink data traffic of the specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uid | number | Yes | Application UID. | + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time downlink data traffic of the application in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getUidRxBytes(20010038).then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getUidTxBytes10+ + +getUidTxBytes(uid: number, callback: AsyncCallback\): void; + +Obtains the real-time uplink data traffic of the specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uid | number | Yes | Application UID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the real-time uplink data traffic of the application in bytes. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getUidTxBytes(20010038, (error, stats) => { + console.log(JSON.stringify(error)) + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.getUidTxBytes10+ + +getUidTxBytes(uid: number): Promise\; + +Obtains the real-time uplink data traffic of the specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uid | number | Yes | Application UID. | + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\ | Promise used to return the result, which is the real-time uplink data traffic of the application in bytes.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103005 | Failed to read map. | +| 2103011 | Failed to create map. | + +**Example** + +```js + statistics.getUidTxBytes(20010038).then(function (stats) { + console.log(JSON.stringify(stats)) + }) +``` + +## statistics.on('netStatsChange')10+ + +on(type: 'netStatsChange', callback: Callback\<{ iface: string, uid?: number }>): void + +Subscribes to data traffic change events. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | ---------- | +| type | string | Yes | Event type. This field has a fixed value of **netStatsChange**.| +| callback | Callback\<{ iface: string, uid?: number }\> | Yes | Callback invoked when the data traffic changes.
**iface**: NIC name.
**uid**: application UID.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | + +**Example** + +```js + statistics.on('netStatsChange', (data) => { + console.log('on netStatsChange' + JSON.stringify(data)); +}); +``` + +## statistics.off('netStatsChange')10+ + +off(type: 'netStatsChange', callback?: Callback\<{ iface: string, uid?: number }>): void; + +Unsubscribes from data traffic change events. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | ---------- | +| type | string | Yes | Event type. This field has a fixed value of **netStatsChange**.| +| callback | Callback\<{ iface: string, uid?: number }\> | No | Callback invoked when the data traffic changes.
**iface**: NIC name.
uid: application UID.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | + +**Example** + +```js +let callback = data => { + console.log("on netStatsChange, data:" + JSON.stringify(data)); +} +statistics.on('netStatsChange', callback); +// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +statistics.off('netStatsChange', callback); +statistics.off('netStatsChange'); +``` + +## statistics.getTrafficStatsByIface10+ + +getTrafficStatsByIface(ifaceInfo: IfaceInfo, callback: AsyncCallback\): void; + +Obtains the historical data traffic of the specified NIC. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| ifaceInfo | [IfaceInfo](#ifaceinfo10) | Yes | NIC information. For details, see [IfaceInfo](#ifaceinfo10). | +| callback | AsyncCallback\<[NetStatsInfo](#netstatsinfo10)> | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **statsInfo** is the historical data traffic of the NIC. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103017 | Read data from database failed. | + +**Example** + +```js + let ifaceInfo = { + iface: "wlan0", + startTime: 1685948465, + endTime: 16859485670 + } + + 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)); + console.log("getTrafficStatsByIface packets of received = " + JSON.stringify(statsInfo.rxPackets)); + console.log("getTrafficStatsByIface packets of sent = " + JSON.stringify(statsInfo.txPackets)); + }); +``` + +## statistics.getTrafficStatsByIface10+ + +getTrafficStatsByIface(ifaceInfo: IfaceInfo): Promise\; + +Obtains the historical data traffic of the specified NIC. This API uses a promise to return the result. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| ifaceInfo | [IfaceInfo](#ifaceinfo10) | Yes | NIC information. For details, see [IfaceInfo](#ifaceinfo10). | + +**Return value** +| Type| Description| +| -------- | -------- | +| Promise\<[NetStatsInfo](#netstatsinfo10)> | Promise used to return the result, which is the historical data traffic of the specified NIC.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103017 | Read data from database failed. | + +**Example** + +```js + let ifaceInfo = { + iface: "wlan0", + startTime: 1685948465, + endTime: 16859485670 + } + + statistics.getTrafficStatsByIface().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)); + console.log("getTrafficStatsByIface packets of sent = " + JSON.stringify(statsInfo.txPackets)); + }) +``` + +## statistics.getTrafficStatsByUid10+ + +getTrafficStatsByUid(uidInfo: UidInfo, callback: AsyncCallback\): void; + +Obtains the historical data traffic of the specified application. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uidInfo | [UidInfo](#uidinfo10) | Yes | Application information. For details, see [UidInfo](#uidinfo10). | +| callback | AsyncCallback\<[NetStatsInfo](#netstatsinfo10)> | Yes | Callback used to return the result. If the operation is successful, **error** is **undefined** and **statsInfo** is the historical data traffic of the application. Otherwise, **error** is an error object.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103017 | Read data from database failed. | + +**Example** + +```js + let uidInfo = { + ifaceInfo: { + iface: "wlan0", + startTime: 1685948465, + endTime: 16859485670 + }, + uid: 20010037 + } + + 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)); + console.log("getTrafficStatsByUid packets of received = " + JSON.stringify(statsInfo.rxPackets)); + console.log("getTrafficStatsByUid packets of sent = " + JSON.stringify(statsInfo.txPackets)); + }); +``` + +## statistics.getTrafficStatsByUid10+ + +getTrafficStatsByUid(uidInfo: UidInfo): Promise\; + +Obtains the historical data traffic of the specified application. This API uses a promise to return the result. + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.GET_NETWORK_STATS + +**System capability**: SystemCapability.Communication.NetManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| uidInfo | [UidInfo](#uidinfo10) | Yes | Application information. For details, see [UidInfo](#uidinfo10). | + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise\<[NetStatsInfo](#netstatsinfo10)> | Promise used to return the result, which is the historical data traffic of the specified NIC.| + +**Error codes** + +For details about the error codes, see [Traffic Management Error Codes](../errorcodes/errorcode-net-statistics.md). + +| ID| Error Message | +| ------- | ----------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 2100001 | Invalid parameter value. | +| 2100002 | Operation failed. Cannot connect to service. | +| 2100003 | System internal error. | +| 2103017 | Read data from database failed. | + +**Example** + +```js + let uidInfo = { + ifaceInfo: { + iface: "wlan0", + startTime: 1685948465, + endTime: 16859485670 + }, + uid: 20010037 + } + + statistics.getTrafficStatsByUid(uidInfo).then(function (statsInfo) { + console.log("getTrafficStatsByUid bytes of received = " + JSON.stringify(statsInfo.rxBytes)); + console.log("getTrafficStatsByUid bytes of sent = " + JSON.stringify(statsInfo.txBytes)); + console.log("getTrafficStatsByUid packets of received = " + JSON.stringify(statsInfo.rxPackets)); + console.log("getTrafficStatsByUid packets of sent = " + JSON.stringify(statsInfo.txPackets)); + }) +``` + +## IfaceInfo10+ + +Defines the parameters for querying historical traffic of an NIC. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.Core + +| Name | Type | Mandatory| Description | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| iface | string | Yes| NIC name.| +| startTime | number | Yes| Start time of the query, which is a timestamp in seconds. | +| endTime | number | Yes| End time of the query, which is a timestamp in seconds. | + +## UidInfo10+ + +Defines the parameters for querying historical traffic of an application. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.Core + +| Name | Type | Mandatory| Description | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| ifaceInfo | IfaceInfo\<[IfaceInfo](#ifaceinfo10)> | Yes| NIC name and query time range.| +| uid | number | Yes| Application UID.| + +## NetStatsInfo10+ + +Defines the historical traffic information. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Communication.NetManager.Core + +| Name | Type | Mandatory| Description | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| rxBytes | number | Yes| Downlink traffic data, in bytes.| +| txBytes | number | Yes| Uplink traffic data, in bytes.| +| rxPackets | number | Yes| Number of downlink packets.| +| txPackets | number | Yes| Number of uplink packets.| diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 2050db9a62813fe6fabc01fd98cb9c0997bff43a..13377e7c7c627e5e5cd4e5752745f949726bd735 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -1870,7 +1870,7 @@ radio.getNrOptionMode((err, data) => { getNrOptionMode\(slotId: number, callback: AsyncCallback\\): void -Obtains the NR option mode. This API uses an asynchronous callback to return the result. +Obtains the NR option mode for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. > **NOTE** > @@ -3228,17 +3228,15 @@ Enumerates preferred network modes. Defines the cell information. -**System API**: This is a system API. - **System capability**: SystemCapability.Telephony.CoreService | Name | Type | Mandatory| Description | | ----------------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | networkType | [NetworkType](#networktype) | Yes | Network type of the cell. | -| isCamped | boolean | Yes | Cell status. | -| timeStamp | number | Yes | Timestamp when cell information is obtained. | +| isCamped | boolean | Yes | Cell status.
**System API**: This is a system API. | +| timeStamp | number | Yes | Timestamp when cell information is obtained.
**System API**: This is a system API. | | signalInformation | [SignalInformation](#signalinformation) | Yes | Signal information. | -| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | Yes | CDMA cell information\|GSM cell information\|LTE cell information\|NR cell information\|TD-SCDMA cell information| +| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | Yes | CDMA cell information\|GSM cell information\|LTE cell information\|NR cell information\|TD-SCDMA cell information
**System API**: This is a system API.| ## CdmaCellInformation8+ diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 0b991202add9b4a0480f3990ccc7f1775f95f3ba..406339fa52423ebf5b29d83f9933b47280ea7b9d 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -1,4 +1,4 @@ -# @ohos.resourceManager (Resource Manager) +# @ohos.resourceManager (Resource Management) The **resourceManager** module provides APIs to obtain information about application resources based on the current configuration, including the language, region, screen direction, MCC/MNC, as well as device capability and density. @@ -3506,7 +3506,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ### getColorByName10+ -getStringByName(resName: string): Promise<number> +getColorByName(resName: string): Promise<number> Obtains the color value corresponding to the specified resource name. This API uses a promise to return the result. diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index 6e89fa67f9e48752ca11967eb4be365554c9cf17..f7d978eb79961eec5fc32486a6cb0af78fb6eaa9 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -34,7 +34,7 @@ let udp = socket.constructUDPSocketInstance(); ## UDPSocket7+ -Defines a **UDPSocket** connection. Before invoking UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object. +Defines a UDPSocket connection. Before calling UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object. ### bind7+ @@ -355,7 +355,7 @@ promise.then(err => { setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\): void -Sets other attributes of the UDPSocket connection. This API uses an asynchronous callback to return the result. +Sets other properties of the UDPSocket connection. This API uses an asynchronous callback to return the result. > **NOTE** > This API can be called only after **bind** is successfully called. @@ -408,7 +408,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { setExtraOptions(options: UDPExtraOptions): Promise\ -Sets other attributes of the UDPSocket connection. This API uses a promise to return the result. +Sets other properties of the UDPSocket connection. This API uses a promise to return the result. > **NOTE** > This API can be called only after **bind** is successfully called. @@ -472,7 +472,7 @@ Enables listening for message receiving events of the UDPSocket connection. This | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | Yes | Callback used to return the result. | **Example** @@ -506,7 +506,7 @@ Disables listening for message receiving events of the UDPSocket connection. Thi | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result. | **Example** @@ -524,7 +524,7 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } udp.on('message', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. udp.off('message', callback); udp.off('message'); ``` @@ -541,7 +541,7 @@ Enables listening for data packet message events or close events of the UDPSocke | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **listening**: data packet message event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **listening**: data packet message event.
- **close**: close event.| | callback | Callback\ | Yes | Callback used to return the result. | **Example** @@ -571,7 +571,7 @@ Disables listening for data packet message events or close events of the UDPSock | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **listening**: data packet message event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **listening**: data packet message event.
- **close**: close event.| | callback | Callback\ | No | Callback used to return the result. | **Example** @@ -582,14 +582,14 @@ let callback1 = () => { console.log("on listening, success"); } udp.on('listening', callback1); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. udp.off('listening', callback1); udp.off('listening'); let callback2 = () => { console.log("on close, success"); } udp.on('close', callback2); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. udp.off('close', callback2); udp.off('close'); ``` @@ -606,7 +606,7 @@ Enables listening for error events of the UDPSocket connection. This API uses an | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | Yes | Callback used to return the result. | **Example** @@ -633,7 +633,7 @@ Disables listening for error events of the UDPSocket connection. This API uses a | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | No | Callback used to return the result. | **Example** @@ -644,7 +644,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } udp.on('error', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. udp.off('error', callback); udp.off('error'); ``` @@ -739,7 +739,7 @@ let tcp = socket.constructTCPSocketInstance(); ## TCPSocket7+ -Defines a TCPSocket connection. Before invoking TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object. +Defines a TCPSocket connection. Before calling TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object. ### bind7+ @@ -1358,7 +1358,7 @@ Enables listening for message receiving events of the TCPSocket connection. This | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | Yes | Callback used to return the result. | **Example** @@ -1392,7 +1392,7 @@ Disables listening for message receiving events of the TCPSocket connection. Thi | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result. | **Example** @@ -1410,7 +1410,7 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } tcp.on('message', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcp.off('message', callback); tcp.off('message'); ``` @@ -1427,7 +1427,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event.
- **close**: close event.| | callback | Callback\ | Yes | Callback used to return the result. | **Example** @@ -1457,7 +1457,7 @@ Disables listening for connection or close events of the TCPSocket connection. T | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event.
- **close**: close event.| | callback | Callback\ | No | Callback used to return the result. | **Example** @@ -1468,14 +1468,14 @@ let callback1 = () => { console.log("on connect success"); } tcp.on('connect', callback1); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcp.off('connect', callback1); tcp.off('connect'); let callback2 = () => { console.log("on close success"); } tcp.on('close', callback2); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcp.off('close', callback2); tcp.off('close'); ``` @@ -1492,7 +1492,7 @@ Enables listening for error events of the TCPSocket connection. This API uses an | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | Yes | Callback used to return the result. | **Example** @@ -1519,7 +1519,7 @@ Disables listening for error events of the TCPSocket connection. This API uses a | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | No | Callback used to return the result. | **Example** @@ -1530,7 +1530,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } tcp.on('error', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcp.off('error', callback); tcp.off('error'); ``` @@ -1596,7 +1596,7 @@ let tcpServer = socket.constructTCPSocketServerInstance(); ## TCPSocketServer10+ -Defines a TCPSocketServer connection. Before invoking TCPSocketServer APIs, you need to call [socket.constructTCPSocketServerInstance](#socketconstructtcpsocketserverinstance10) to create a **TCPSocketServer** object. +Defines a TCPSocketServer connection. Before calling TCPSocketServer APIs, you need to call [socket.constructTCPSocketServerInstance](#socketconstructtcpsocketserverinstance10) to create a **TCPSocketServer** object. ### listen10+ @@ -1916,7 +1916,7 @@ Enables listening for TCPSocketServer connection events. This API uses an asynch | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event| +| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event.| | callback | Callback<[TCPSocketConnection](#tcpsocketconnection10)> | Yes | Callback used to return the result. | **Error codes** @@ -1949,7 +1949,7 @@ Disables listening for TCPSocketServer connection events. This API uses an async | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event| +| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event.| | callback | Callback<[TCPSocketConnection](#tcpsocketconnection10)> | No | Callback used to return the result. | **Error codes** @@ -1966,7 +1966,7 @@ let callback = data => { console.log('on connect message: ' + JSON.stringify(data)); } tcpServer.on('connect', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcpServer.off('connect', callback); tcpServer.off('connect'); ``` @@ -1983,7 +1983,7 @@ Enables listening for error events of the TCPSocketServer connection. This API u | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | Yes | Callback used to return the result. | **Error codes** @@ -2016,7 +2016,7 @@ Disables listening for error events of the TCPSocketServer connection. This API | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | No | Callback used to return the result. | **Error codes** @@ -2033,14 +2033,17 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } tcpServer.on('error', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tcpServer.off('error', callback); tcpServer.off('error'); ``` ## TCPSocketConnection10+ -Defines a **TCPSocketConnection** object, that is, the connection between the TCPSocket client and the server. Before invoking TCPSocketConnection APIs, you need to obtain a **TCPSocketConnection** object. +Defines a **TCPSocketConnection** object, that is, the connection between the TCPSocket client and the server. Before calling TCPSocketConnection APIs, you need to obtain a **TCPSocketConnection** object. + +> **NOTE** +> The TCPSocket client can call related APIs through the **TCPSocketConnection** object only after a connection is successfully established between the TCPSocket client and the server. **System capability**: SystemCapability.Communication.NetStack @@ -2312,7 +2315,7 @@ Enables listening for **message** events of a **TCPSocketConnection** object. Th | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo7)}> | Yes | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information. | **Error codes** @@ -2331,7 +2334,7 @@ tcpServer.on('connect', function(client) { for (var i = 0; i < value.message.length; i++) { let messages = value.message[i]; let message = String.fromCharCode(messages); - messageView += item; + messageView += message; } console.log('on message message: ' + JSON.stringify(messageView)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); @@ -2354,8 +2357,8 @@ Disables listening for **message** events of a **TCPSocketConnection** object. T | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| -| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo7)}> | No | Callback used to return the result. **message**: received message.
**remoteInfo**: socket connection information. | +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| +| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo7)}> | No | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information. | **Error codes** @@ -2371,7 +2374,7 @@ let callback = value => { for (var i = 0; i < value.message.length; i++) { let messages = value.message[i]; let message = String.fromCharCode(messages); - messageView += item; + messageView += message; } console.log('on message message: ' + JSON.stringify(messageView)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); @@ -2379,7 +2382,7 @@ let callback = value => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { client.on('message', callback); - // You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. client.off('message', callback); client.off('message'); }); @@ -2397,7 +2400,7 @@ Enables listening for **close** events of a **TCPSocketConnection** object. This | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ----------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**close**: close event| +| type | string | Yes | Type of the event to subscribe to.
**close**: close event.| | callback | Callback\ | Yes | Callback used to return the result. | **Error codes** @@ -2432,7 +2435,7 @@ Disables listening for **close** events of a **TCPSocketConnection** object. Thi | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ----------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**close**: close event| +| type | string | Yes | Type of the event to subscribe to.
**close**: close event.| | callback | Callback\ | No | Callback used to return the result. | **Error codes** @@ -2450,7 +2453,7 @@ let callback = () => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { client.on('close', callback); - // You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. client.off('close', callback); client.off('close'); }); @@ -2468,7 +2471,7 @@ Enables listening for **error** events of a **TCPSocketConnection** object. This | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | Yes | Callback used to return the result. | **Error codes** @@ -2503,7 +2506,7 @@ Disables listening for **error** events of a **TCPSocketConnection** object. Thi | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | No | Callback used to return the result. | **Error codes** @@ -2521,7 +2524,7 @@ let callback = err => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { client.on('error', callback); - // You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. client.off('error', callback); client.off('error'); }); @@ -2555,7 +2558,7 @@ let tls = socket.constructTLSSocketInstance(); ## TLSSocket9+ -Defines a TLSSocket connection. Before invoking TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object. +Defines a TLSSocket connection. Before calling TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object. ### bind9+ @@ -2719,7 +2722,7 @@ promise.then(() => { setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): void -Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses an asynchronous callback to return the result. +Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Communication.NetStack @@ -2771,7 +2774,7 @@ tls.setExtraOptions({ setExtraOptions(options: TCPExtraOptions): Promise\ -Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses a promise to return the result. +Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses a promise to return the result. **System capability**: SystemCapability.Communication.NetStack @@ -2834,7 +2837,7 @@ Enables listening for **message** events of the TLSSocket connection. This API u | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| | callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | Yes | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information.| **Example** @@ -2868,8 +2871,8 @@ Disables listening for **message** events of the TLSSocket connection. This API | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | -| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event| -| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result. **message**: received message.
**remoteInfo**: socket connection information.| +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| +| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information.| **Example** @@ -2886,14 +2889,14 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } tls.on('message', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tls.off('message', callback); ``` ### on('connect' | 'close')9+ on(type: 'connect' | 'close', callback: Callback\): void -Enables listening for connection or close events of the TLSSocket connection. This API uses an asynchronous callback to return the result. +Enables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Communication.NetStack @@ -2901,7 +2904,7 @@ Enables listening for connection or close events of the TLSSocket connection. Th | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event.
- **close**: close event.| | callback | Callback\ | Yes | Callback used to return the result. | **Example** @@ -2920,7 +2923,7 @@ tls.on('close', () => { off(type: 'connect' | 'close', callback?: Callback\): void -Disables listening for connection or close events of the TLSSocket connection. This API uses an asynchronous callback to return the result. +Disables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. > **NOTE** > You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. @@ -2931,7 +2934,7 @@ Disables listening for connection or close events of the TLSSocket connection. T | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event
- **close**: close event| +| type | string | Yes | Type of the event to subscribe to.
- **connect**: connection event.
- **close**: close event.| | callback | Callback\ | No | Callback used to return the result. | **Example** @@ -2942,14 +2945,14 @@ let callback1 = () => { console.log("on connect success"); } tls.on('connect', callback1); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tls.off('connect', callback1); tls.off('connect'); let callback2 = () => { console.log("on close success"); } tls.on('close', callback2); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tls.off('close', callback2); ``` @@ -2965,7 +2968,7 @@ Enables listening for error events of the TLSSocket connection. This API uses an | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | Yes | Callback used to return the result. | **Example** @@ -2992,7 +2995,7 @@ Disables listening for error events of the TLSSocket connection. This API uses a | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ------------------------------------ | -| type | string | Yes | Type of the event to subscribe to.
**error**: error event| +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| | callback | ErrorCallback | No | Callback used to return the result. | **Example** @@ -3003,7 +3006,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } tls.on('error', callback); -// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. tls.off('error', callback); ``` @@ -3011,7 +3014,7 @@ tls.off('error', callback); connect(options: TLSConnectOptions, callback: AsyncCallback\): void -Sets up a TLSSocket connection, and creates and initializes a TLS session after successful binding of the local IP address and port number of the TLSSocket connection. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result. +Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Communication.NetStack @@ -3105,7 +3108,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => { connect(options: TLSConnectOptions): Promise\ -Sets up a TLSSocket connection, and creates and initializes a TLS session after successful binding of the local IP address and port number of the TLSSocket connection. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result. +Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result. **System capability**: SystemCapability.Communication.NetStack @@ -3789,3 +3792,2001 @@ Enumerates TLS protocol versions. Defines the certificate raw data. **System capability**: SystemCapability.Communication.NetStack + +## socket.constructTLSSocketServerInstance10+ + +constructTLSSocketServerInstance(): TLSSocketServer + +Creates a **TLSSocketServer** object. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| :------------------------------------ | :---------------------------- | +| [TLSSocketServer](#tlssocketserver10) | **TLSSocketServer** object.| + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +``` + +## TLSSocketServer10+ + +Defines a TLSSocketServer connection. Before calling TLSSocketServer APIs, you need to call [socket.constructTLSSocketServerInstance](#socketconstructtlssocketserverinstance10) to create a **TLSSocketServer** object. + +### listen10+ + +listen(options: TLSConnectOptions, callback: AsyncCallback\): void + +Listens to client connections after **bind** is successfully called. This API uses an asynchronous callback to return the result. After a connection is established, a TLS session will be created and initialized and a certificate key will be loaded and verified. + +**Required permissions**: ohos.permission.INTERNET + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | ------------------------------------------------ | +| options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the connection. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------- | +| 401 | Parameter error. | +| 201 | Permission denied. | +| 2300002 | System internal error. | +| 2303109 | Bad file number. | +| 2303111 | Resource temporarily unavailable try again. | +| 2303198 | Address already in use. | +| 2303199 | Cannot assign requested address. | +| 2303501 | SSL is null. | +| 2303502 | Error in tls reading. | +| 2303503 | Error in tls writing | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); +}); +``` + +### listen10+ + +listen(options: TLSConnectOptions): Promise\ + +Listens to client connections after **bind** is successfully called. This API uses a promise to return the result. After a connection is established, a TLS session will be created and initialized and a certificate key will be loaded and verified. + +**Required permissions**: ohos.permission.INTERNET + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ---------------------------------------- | ---- | ------------------ | +| options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the connection.| + +**Return value** + +| Type | Description | +| --------------- | --------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------- | +| 401 | Parameter error. | +| 201 | Permission denied. | +| 2300002 | System internal error. | +| 2303109 | Bad file number. | +| 2303111 | Resource temporarily unavailable try again. | +| 2303198 | Address already in use. | +| 2303199 | Cannot assign requested address. | +| 2303501 | SSL is null. | +| 2303502 | Error in tls reading. | +| 2303503 | Error in tls writing | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); +}); +``` + +### getState10+ + +getState(callback: AsyncCallback\): void + +Obtains the status of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\<[SocketStateBase](#socketstatebase7)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLSSocketServer connection is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 401 | Parameter error. | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); + +tlsServer.getState((err, data) => { + if (err) { + console.log('getState fail'); + return; + } + console.log('getState success:' + JSON.stringify(data)); +}); +``` + +### getState10+ + +getState(): Promise\ + +Obtains the status of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| :--------------------------------------------- | :----------------------------------------------------------- | +| Promise\<[SocketStateBase](#socketstatebase7)> | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +let promise = tlsServer.getState(); +promise.then(() => { + console.log('getState success'); +}).catch(err => { + console.log('getState fail'); +}); +``` + +### setExtraOptions10+ + +setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): void + +Sets other properties of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ------------------------------------------------ | +| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 401 | Parameter error. | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.setExtraOptions({ + keepAlive: true, + OOBInline: true, + TCPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, +}, err => { + if (err) { + console.log('setExtraOptions fail'); + return; + } + console.log('setExtraOptions success'); +}); +``` + +### setExtraOptions10+ + +setExtraOptions(options: TCPExtraOptions): Promise\ + +Sets other properties of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------ | ---- | ------------------------------- | +| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection.| + +**Return value** + +| Type | Description | +| :-------------- | :-------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 401 | Parameter error. | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +let promise = tlsServer.setExtraOptions({ + keepAlive: true, + OOBInline: true, + TCPNoDelay: true, + socketLinger: { on: true, linger: 10 }, + receiveBufferSize: 1000, + sendBufferSize: 1000, + reuseAddress: true, + socketTimeout: 3000, +}); +promise.then(() => { + console.log('setExtraOptions success'); +}).catch(err => { + console.log('setExtraOptions fail'); +}); +``` + +### getCertificate10+ + +getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void + +Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------------- | +| callback | AsyncCallback\<[X509CertRawData](#x509certrawdata9)\> | Yes | Callback used to return the result. If the operation is successful, the local certificate is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303504 | Error looking up x509. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.getCertificate((err, data) => { + if (err) { + console.log("getCertificate callback error = " + err); + } else { + console.log("getCertificate callback = " + data); + } +}); +``` + +### getCertificate10+ + +getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> + +Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses a promise to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| ----------------------------------------------- | ------------------------------------------------------------ | +| Promise\<[X509CertRawData](#x509certrawdata9)\> | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 2303501 | SSL is null. | +| 2303504 | Error looking up x509. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.getCertificate().then(data => { + console.log(data); +}).catch(err => { + console.error(err); +}); +``` + +### getProtocol10+ + +getProtocol(callback: AsyncCallback\): void + +Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ---------------------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303505 | Error occurred in the tls system call. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.getProtocol((err, data) => { + if (err) { + console.log("getProtocol callback error = " + err); + } else { + console.log("getProtocol callback = " + data); + } +}); +``` + +### getProtocol10+ + +getProtocol():Promise\ + +Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses a promise to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| ----------------- | ------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 2303501 | SSL is null. | +| 2303505 | Error occurred in the tls system call. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.getProtocol().then(data => { + console.log(data); +}).catch(err => { + console.error(err); +}); +``` + +### on('connect') + +on(type: 'connect', callback: Callback\): void + +Enables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event.| +| callback | Callback<[TLSSocketConnection](#tlssocketconnection10)> | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(data) { + console.log(JSON.stringify(data)) +}); +``` + +### off('connect') + +off(type: 'connect', callback?: Callback\): void + +Disables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result. + +> **NOTE** +> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**connect**: connection event.| +| callback | Callback<[TLSSocketConnection](#tlssocketconnection10)> | No | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let callback = data => { + console.log('on connect message: ' + JSON.stringify(data)); +} +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', callback); +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. +tlsServer.off('connect', callback); +tlsServer.off('connect'); +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +Enables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result. + +> **NOTE** +> This API can be called only after **listen** is successfully called. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ------------------------------------ | +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| +| callback | ErrorCallback | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('error', err => { + console.log("on error, err:" + JSON.stringify(err)) +}); +``` + +### off('error') + +off(type: 'error', callback?: ErrorCallback): void + +Disables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result. + +> **NOTE** +> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ------------------------------------ | +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| +| callback | ErrorCallback | No | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let callback = err => { + console.log("on error, err:" + JSON.stringify(err)); +} +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('error', callback); +// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. +tlsServer.off('error', callback); +tlsServer.off('error'); +``` + +## TLSSocketConnection10+ + +Defines a **TLSSocketConnection** object, that is, the connection between the TLSSocket client and the server. Before calling TLSSocketConnection APIs, you need to obtain a **TLSSocketConnection** object. + +> **NOTE** +> The TLSSocket client can call related APIs through the **TLSSocketConnection** object only after a connection is successfully established between the TLSSocket client and the server. + +**System capability**: SystemCapability.Communication.NetStack + +### Attributes + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------- | +| clientId | number | Yes | ID of the connection between the client and TLSSocketServer.| + +### send10+ + +send(data: string, callback: AsyncCallback\): void + +Sends a message to the client after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------------------------------ | +| data | string | Yes | Parameters for sending data over the TLSSocketServer connection. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303503 | Error in tls writing. | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.send({data: 'Hello, client!'}, err => { + if (err) { + console.log('send fail'); + return; + } + console.log('send success'); + }); +}); +``` + +### send10+ + +send(data: string): Promise\ + +Sends a message to the server after a TLSSocketServer connection is established. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------- | +| data | string | Yes | Parameters required for the TLSSocketServer connection.| + +**Return value** + +| Type | Description | +| --------------- | --------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303503 | Error in tls writing. | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + let promise = client.send({data: 'Hello, client!'}); + promise.then(() => { + console.log('send success'); + }).catch(err => { + console.log('send fail'); + }); +}); +``` + +### close10+ + +close(callback: AsyncCallback\): void + +Closes a TLSSocketServer connection. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.close(err => { + if (err) { + console.log('close fail'); + return; + } + console.log('close success'); + }); +}); +``` + +### close10+ + +close(): Promise\ + +Closes a TLSSocketServer connection. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| --------------- | --------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 2303501 | SSL is null. | +| 2303505 | Error occurred in the tls system call. | +| 2303506 | Error clearing tls connection. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + let promise = client.close(); + promise.then(() => { + console.log('close success'); + }).catch(err => { + console.log('close fail'); + }); +}); +``` + +### getRemoteAddress10+ + +getRemoteAddress(callback: AsyncCallback\): void + +Obtains the remote address of a TLSSocketServer connection. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\<[NetAddress](#netaddress7)\> | Yes | Callback used to return the result. If the operation is successful, the remote address is returned. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 401 | Parameter error. | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.getRemoteAddress((err, data) => { + if (err) { + console.log('getRemoteAddress fail'); + return; + } + console.log('getRemoteAddress success:' + JSON.stringify(data)); + }); +}); +``` + +### getRemoteAddress10+ + +getRemoteAddress(): Promise\ + +Obtains the remote address of a TLSSocketServer connection. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| :----------------------------------- | :----------------------------------------------------------- | +| Promise\<[NetAddress](#netaddress7)> | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------- | +| 2303188 | Socket operation on non-socket. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.getRemoteAddress().then(data => { + console.log('getRemoteAddress success:' + JSON.stringify(data)); + }).catch(err => { + console.error(err); + }); +}); +``` + +### getRemoteCertificate10+ + +getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void + +Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. It applies only to the scenario where the client sends a certificate to the server. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------- | +| callback | AsyncCallback\<[X509CertRawData](#x509certrawdata9)\> | Yes | Callback used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.getRemoteCertificate((err, data) => { + if (err) { + console.log("getRemoteCertificate callback error = " + err); + } else { + console.log("getRemoteCertificate callback = " + data); + } + }); +}); +``` + +### getRemoteCertificate10+ + +getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> + +Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses a promise to return the result. It applies only to the scenario where the client sends a certificate to the server. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| ----------------------------------------------- | ------------------------------------------------------------ | +| Promise\<[X509CertRawData](#x509certrawdata9)\> | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 2303501 | SSL is null. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.getRemoteCertificate().then(data => { + console.log('getRemoteCertificate success:' + JSON.stringify(data)); + }).catch(err => { + console.error(err); + }); +}); +``` + +### getCipherSuite10+ + +getCipherSuite(callback: AsyncCallback\\>): void + +Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\\> | Yes | Callback used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2303502 | Error in tls reading. | +| 2303505 | Error occurred in the tls system call. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.getCipherSuite((err, data) => { + if (err) { + console.log("getCipherSuite callback error = " + err); + } else { + console.log("getCipherSuite callback = " + data); + } + }); +}); +``` + +### getCipherSuite10+ + +getCipherSuite(): Promise\\> + +Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| -------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result. If the operation fails, an error message is returned.| + +**Error codes** + +| ID| Error Message | +| -------- | -------------------------------------- | +| 2303501 | SSL is null. | +| 2303502 | Error in tls reading. | +| 2303505 | Error occurred in the tls system call. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.getCipherSuite().then(data => { + console.log('getCipherSuite success:' + JSON.stringify(data)); + }).catch(err => { + console.error(err); + }); +}); +``` + +### getSignatureAlgorithms10+ + +getSignatureAlgorithms(callback: AsyncCallback\\>): void + +Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------------------- | ---- | ---------------------------------- | +| callback | AsyncCallback\\> | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 401 | Parameter error. | +| 2303501 | SSL is null. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.getSignatureAlgorithms((err, data) => { + if (err) { + console.log("getSignatureAlgorithms callback error = " + err); + } else { + console.log("getSignatureAlgorithms callback = " + data); + } + }); +}); +``` + +### getSignatureAlgorithms10+ + +getSignatureAlgorithms(): Promise\\> + +Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Return value** + +| Type | Description | +| -------------------------- | --------------------------------------------- | +| Promise\\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------- | +| 2303501 | SSL is null. | +| 2300002 | System internal error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.getSignatureAlgorithms().then(data => { + console.log("getSignatureAlgorithms success" + data); + }).catch(err => { + console.error(err); + }); +}); +``` + +### on('message')10+ + +on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void + +Enables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| +| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo7)}> | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('message', value => { + let messageView = ''; + for (var i = 0; i < value.message.length; i++) { + let messages = value.message[i] + let message = String.fromCharCode(messages); + messageView += message; + } + console.log('on message message: ' + JSON.stringify(messageView)); + console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); + }); +}); +``` + +### off('message')10+ + +off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void + +Disables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +> **NOTE** +> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| +| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo7)}> | No | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let callback = value => { + let messageView = ''; + for (var i = 0; i < value.message.length; i++) { + let messages = value.message[i] + let message = String.fromCharCode(messages); + messageView += message; + } + console.log('on message message: ' + JSON.stringify(messageView)); + console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); +} +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('message', callback); + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. + client.off('message', callback); + client.off('message'); +}); +``` + +### on('close')10+ + +on(type: 'close', callback: Callback\): void + +Enables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------- | ---- | ----------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**close**: close event.| +| callback | Callback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('close', () => { + console.log("on close success") + }); +}); +``` + +### off('close')10+ + +on(type: 'close', callback: Callback\): void + +Disables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +> **NOTE** +> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------- | ---- | ----------------------------------- | +| type | string | Yes | Type of the event to subscribe to.
**close**: close event.| +| callback | Callback\ | No | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let callback = () => { + console.log("on close success"); +} +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('close', callback); + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. + client.off('close', callback); + client.off('close'); +}); +``` + +### on('error')10+ + +on(type: 'error', callback: ErrorCallback): void + +Enables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ------------------------------------ | +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| +| callback | ErrorCallback | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "192.168.xx.xxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options, err => { + console.log("listen callback error" + err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('error', err => { + console.log("on error, err:" + JSON.stringify(err)) + }); +}); +``` + +### off('error')10+ + +off(type: 'error', callback?: ErrorCallback): void + +Disables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. + +> **NOTE** +> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Communication.NetStack + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ------------------------------------ | +| type | string | Yes | Type of the event to subscribe to.
**error**: error event.| +| callback | ErrorCallback | No | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------- | +| 401 | Parameter error. | + +**Example** + +```js +let callback = err => { + console.log("on error, err:" + JSON.stringify(err)); +} +let tlsServer = socket.constructTLSSocketServerInstance(); +let options = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: "xxxx", + port: 8080, + family: 1, + }, + secureOptions: { + key: "xxxx", + cert: "xxxx", + ca: ["xxxx"], + password: "xxxx", + protocols: [socket.Protocol.TLSv12], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", + }, +}; +tlsServer.listen(options).then(() => { + console.log("listen callback success"); +}).catch(err => { + console.log(err); + return; +}); +tlsServer.on('connect', function(client) { + client.on('error', callback); + // You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. + client.off('error', callback); + client.off('error'); +}); +``` diff --git a/en/application-dev/reference/errorcodes/Readme-EN.md b/en/application-dev/reference/errorcodes/Readme-EN.md index 8c91c3d1205b3bd853b05dfa015a3f4e06a3290f..6fb0ba6ab8a22d3f47b0826e42d854ae62e84f62 100644 --- a/en/application-dev/reference/errorcodes/Readme-EN.md +++ b/en/application-dev/reference/errorcodes/Readme-EN.md @@ -56,6 +56,7 @@ - [Ethernet Connection Error Codes](errorcode-net-ethernet.md) - [Network Sharing Error Codes](errorcode-net-sharing.md) - [mDNS Error Codes](errorcode-net-mdns.md) + - [Traffic Management Error Codes](errorcode-net-statistics.md) - Connectivity - [Bluetooth Error Codes](errorcode-bluetoothManager.md) - [Wi-Fi Error Codes](errorcode-wifi.md) diff --git a/en/application-dev/reference/errorcodes/errorcode-net-statistics.md b/en/application-dev/reference/errorcodes/errorcode-net-statistics.md new file mode 100644 index 0000000000000000000000000000000000000000..4c3a098baccceca5d06c98c438ff693b85b01d1c --- /dev/null +++ b/en/application-dev/reference/errorcodes/errorcode-net-statistics.md @@ -0,0 +1,136 @@ +# Traffic Management Error Codes + +> **NOTE** +> +> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md). + +## 2100001 Invalid Parameters + +**Error Information** + +Invalid parameter value. + +**Description** + +This error code is reported if any input parameter value is incorrect. + +**Possible Causes** + +The end time is earlier than the start time. + +**Solution** + +Check whether the start time and end time are properly set. + + +## 2100002 Service Connection Failure + +**Error Information** + +Operation failed. Cannot connect to service. + +**Description** + +This error code is reported if a service connection failure occurs. + +**Possible Causes** + +The service is abnormal. + +**Solution** + +Check whether system services are running properly. + +## 2100003 System Internal Error + +**Error Information** + +System internal error. + +**Description** + +This error code is reported if an internal system error occurs. + +**Possible Causes** + +1. The memory is abnormal. + +2. A null pointer is present. + +**Solution** + +1. Check whether the memory space is sufficient. If not, clear the memory and try again. + +2. Check whether the system is normal. If not, try again later or restart the device. + +## 2103005 Failed to Read the System Map + +**Error Information** + +Failed to read map. + +**Description** + +This error code is reported if the attempt to read the system map fails. + +**Possible Causes** + +The attempt to read traffic data on the kernel map object fails. + +**Solution** + +Check whether traffic is generated for the specified NIC or application. + +## 2103011 Failed to Create a System Map + +**Error Information** + +Failed to create map. + +**Description** + +This error code is reported if the attempt to create a kernel map object fails. + +**Possible Causes** + +No traffic is generated on the NIC and therefore a kernel traffic object has not been created. + +**Solution** + +Ensure that traffic is generated on the NIC. + +## 2103012 Failed to Obtain the NIC Name + +**Error Information** + +Get iface name failed. + +**Description** + +This error code is reported if the attempt to obtain the NIC name fails. + +**Possible Causes** + +The NIC name does not exist on the local host. + +**Solution** + +Check whether the input NIC name is correct. + +## 2103017 Failed to Read the Database + +**Error Information** + +Read data from database failed. + +**Description** + +This error code is reported if the attempt to read the database fails. + +**Possible Causes** + +The database is damaged. + +**Solution** + +Check whether the database file on the local host is damaged.