1# @ohos.net.statistics (Traffic Management) 2 3The **statistics** module provides APIs to query real-time or historical data traffic by the specified network interface card (NIC) or user ID (UID). 4 5> **NOTE** 6> 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. 7 8## Modules to Import 9 10```js 11import { statistics } from '@kit.NetworkKit'; 12``` 13 14## statistics.getIfaceRxBytes<sup>10+</sup> 15 16getIfaceRxBytes(nic: string, callback: AsyncCallback\<number>): void; 17 18Obtains the real-time downlink data traffic of the specified NIC. This API uses an asynchronous callback to return the result. 19 20**System capability**: SystemCapability.Communication.NetManager.Core 21 22**Parameters** 23 24| Name | Type | Mandatory| Description | 25| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 26| nic | string | Yes | NIC name. | 27| callback | AsyncCallback\<number> | 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. | 28 29**Error codes** 30 31For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 32 33| ID| Error Message | 34| --------- | -------------------------------------------- | 35| 401 | Parameter error. | 36| 2100002 | Failed to connect to the service. | 37| 2100003 | System internal error. | 38| 2103005 | Failed to read the system map. | 39| 2103011 | Failed to create a system map. | 40| 2103012 | Failed to obtain the NIC name. | 41 42**Example** 43 44```js 45import { BusinessError } from '@kit.BasicServicesKit'; 46import { statistics } from '@kit.NetworkKit'; 47 48statistics.getIfaceRxBytes("wlan0", (error: BusinessError, stats: number) => { 49 console.log(JSON.stringify(error)); 50 console.log(JSON.stringify(stats)); 51}); 52``` 53 54## statistics.getIfaceRxBytes<sup>10+</sup> 55 56getIfaceRxBytes(nic: string): Promise\<number>; 57 58Obtains the real-time downlink data traffic of the specified NIC. This API uses a promise to return the result. 59 60**System capability**: SystemCapability.Communication.NetManager.Core 61 62**Parameters** 63 64| Name| Type | Mandatory| Description | 65| ------ | ------ | ---- | ------------------ | 66| nic | string | Yes | NIC name.| 67 68**Return value** 69| Type| Description| 70| -------- | -------- | 71| Promise\<number> | Promise used to return the result, which is the real-time downlink data traffic of the NIC in bytes.| 72 73**Error codes** 74 75For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 76 77| ID| Error Message | 78| --------- | -------------------------------------------- | 79| 401 | Parameter error. | 80| 2100002 | Failed to connect to the service. | 81| 2100003 | System internal error. | 82| 2103005 | Failed to read the system map. | 83| 2103011 | Failed to create a system map. | 84| 2103012 | Failed to obtain the NIC name. | 85 86**Example** 87 88```js 89import { statistics } from '@kit.NetworkKit'; 90 91statistics.getIfaceRxBytes("wlan0").then((stats: number) => { 92 console.log(JSON.stringify(stats)); 93}); 94``` 95 96## statistics.getIfaceTxBytes<sup>10+</sup> 97 98getIfaceTxBytes(nic: string, callback: AsyncCallback\<number>): void; 99 100Obtains the real-time uplink data traffic of the specified NIC. This API uses an asynchronous callback to return the result. 101 102**System capability**: SystemCapability.Communication.NetManager.Core 103 104**Parameters** 105 106| Name | Type | Mandatory| Description | 107| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 108| nic | string | Yes | NIC name. | 109| callback | AsyncCallback\<number> | 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. | 110 111**Error codes** 112 113For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 114 115| ID| Error Message | 116| --------- | -------------------------------------------- | 117| 401 | Parameter error. | 118| 2100002 | Failed to connect to the service. | 119| 2100003 | System internal error. | 120| 2103005 | Failed to read the system map. | 121| 2103011 | Failed to create a system map. | 122| 2103012 | Failed to obtain the NIC name. | 123 124**Example** 125 126```js 127import { BusinessError } from '@kit.BasicServicesKit'; 128import { statistics } from '@kit.NetworkKit'; 129 130statistics.getIfaceTxBytes("wlan0", (error: BusinessError, stats: number) => { 131 console.log(JSON.stringify(error)); 132 console.log(JSON.stringify(stats)); 133}); 134``` 135 136## statistics.getIfaceTxBytes<sup>10+</sup> 137 138getIfaceTxBytes(nic: string): Promise\<number>; 139 140Obtains the real-time uplink data traffic of the specified NIC. This API uses a promise to return the result. 141 142**System capability**: SystemCapability.Communication.NetManager.Core 143 144**Parameters** 145 146| Name| Type | Mandatory| Description | 147| ------ | ------ | ---- | ------------------ | 148| nic | string | Yes | NIC name.| 149 150**Return value** 151| Type| Description| 152| -------- | -------- | 153| Promise\<number> | Promise used to return the result, which is the real-time uplink data traffic of the NIC in bytes.| 154 155**Error codes** 156 157For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 158 159| ID| Error Message | 160| --------- | -------------------------------------------- | 161| 401 | Parameter error. | 162| 2100002 | Failed to connect to the service. | 163| 2100003 | System internal error. | 164| 2103005 | Failed to read the system map. | 165| 2103011 | Failed to create a system map. | 166| 2103012 | Failed to obtain the NIC name. | 167 168**Example** 169 170```js 171import { statistics } from '@kit.NetworkKit'; 172 173statistics.getIfaceTxBytes("wlan0").then((stats: number) => { 174 console.log(JSON.stringify(stats)); 175}); 176``` 177 178## statistics.getCellularRxBytes<sup>10+</sup> 179 180getCellularRxBytes(callback: AsyncCallback\<number>): void; 181 182Obtains the real-time downlink data traffic of a cellular network. This API uses an asynchronous callback to return the result. 183 184**System capability**: SystemCapability.Communication.NetManager.Core 185 186**Parameters** 187 188| Name | Type | Mandatory| Description | 189| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 190| callback | AsyncCallback\<number> | 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. | 191 192**Error codes** 193 194For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 195 196| ID| Error Message | 197| --------- | -------------------------------------------- | 198| 2100002 | Failed to connect to the service. | 199| 2100003 | System internal error. | 200| 2103005 | Failed to read the system map. | 201| 2103011 | Failed to create a system map. | 202| 2103012 | Failed to obtain the NIC name. | 203 204**Example** 205 206```js 207import { BusinessError } from '@kit.BasicServicesKit'; 208import { statistics } from '@kit.NetworkKit'; 209 210statistics.getCellularRxBytes((error: BusinessError, stats: number) => { 211 console.log(JSON.stringify(error)); 212 console.log(JSON.stringify(stats)); 213}); 214``` 215 216## statistics.getCellularRxBytes<sup>10+</sup> 217 218getCellularRxBytes(): Promise\<number>; 219 220Obtains the real-time downlink data traffic of a cellular network. This API uses a promise to return the result. 221 222**System capability**: SystemCapability.Communication.NetManager.Core 223 224**Return value** 225| Type| Description| 226| -------- | -------- | 227| Promise\<number> | Promise used to return the result, which is the real-time downlink data traffic of the cellular network in bytes.| 228 229**Error codes** 230 231For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 232 233| ID| Error Message | 234| --------- | -------------------------------------------- | 235| 2100002 | Failed to connect to the service. | 236| 2100003 | System internal error. | 237| 2103005 | Failed to read the system map. | 238| 2103011 | Failed to create a system map. | 239| 2103012 | Failed to obtain the NIC name. | 240 241**Example** 242 243```js 244import { statistics } from '@kit.NetworkKit'; 245 246statistics.getCellularRxBytes().then((stats: number) => { 247 console.log(JSON.stringify(stats)); 248}); 249``` 250 251## statistics.getCellularTxBytes<sup>10+</sup> 252 253getCellularTxBytes(callback: AsyncCallback\<number>): void; 254 255Obtains the real-time uplink data traffic of a cellular network. This API uses an asynchronous callback to return the result. 256 257**System capability**: SystemCapability.Communication.NetManager.Core 258 259**Parameters** 260 261| Name | Type | Mandatory| Description | 262| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 263| callback | AsyncCallback\<number> | 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. | 264 265**Error codes** 266 267For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 268 269| ID| Error Message | 270| --------- | -------------------------------------------- | 271| 2100002 | Failed to connect to the service. | 272| 2100003 | System internal error. | 273| 2103005 | Failed to read the system map. | 274| 2103011 | Failed to create a system map. | 275| 2103012 | Failed to obtain the NIC name. | 276 277**Example** 278 279```js 280import { BusinessError } from '@kit.BasicServicesKit'; 281import { statistics } from '@kit.NetworkKit'; 282 283statistics.getCellularTxBytes((error: BusinessError, stats: number) => { 284 console.log(JSON.stringify(error)); 285 console.log(JSON.stringify(stats)); 286}); 287``` 288 289## statistics.getCellularTxBytes<sup>10+</sup> 290 291getCellularTxBytes(): Promise\<number>; 292 293Obtains the real-time uplink data traffic of a cellular network. This API uses a promise to return the result. 294 295**System capability**: SystemCapability.Communication.NetManager.Core 296 297**Return value** 298| Type| Description| 299| -------- | -------- | 300| Promise\<number> | Promise used to return the result, which is the real-time uplink data traffic of the cellular network in bytes.| 301 302**Error codes** 303 304For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 305 306| ID| Error Message | 307| --------- | -------------------------------------------- | 308| 2100002 | Failed to connect to the service. | 309| 2100003 | System internal error. | 310| 2103005 | Failed to read the system map. | 311| 2103011 | Failed to create a system map. | 312| 2103012 | Failed to obtain the NIC name. | 313 314**Example** 315 316```js 317import { statistics } from '@kit.NetworkKit'; 318 319statistics.getCellularTxBytes().then((stats: number) => { 320 console.log(JSON.stringify(stats)); 321}); 322``` 323 324## statistics.getAllRxBytes<sup>10+</sup> 325 326getAllRxBytes(callback: AsyncCallback\<number>): void; 327 328Obtains the real-time downlink data traffic of all NICs. This API uses an asynchronous callback to return the result. 329 330**System capability**: SystemCapability.Communication.NetManager.Core 331 332**Parameters** 333 334| Name | Type | Mandatory| Description | 335| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 336| callback | AsyncCallback\<number> | 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. | 337 338**Error codes** 339 340For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 341 342| ID| Error Message | 343| --------- | -------------------------------------------- | 344| 2100002 | Failed to connect to the service. | 345| 2100003 | System internal error. | 346| 2103005 | Failed to read the system map. | 347| 2103011 | Failed to create a system map. | 348 349**Example** 350 351```js 352import { statistics } from '@kit.NetworkKit'; 353import { BusinessError } from '@kit.BasicServicesKit'; 354 355statistics.getAllRxBytes((error: BusinessError, stats: number) => { 356 console.log(JSON.stringify(error)); 357 console.log(JSON.stringify(stats)); 358}); 359``` 360 361## statistics.getAllRxBytes<sup>10+</sup> 362 363getAllRxBytes(): Promise\<number>; 364 365Obtains the real-time downlink data traffic of all NICs. This API uses a promise to return the result. 366 367**System capability**: SystemCapability.Communication.NetManager.Core 368 369**Return value** 370| Type| Description| 371| -------- | -------- | 372| Promise\<number> | Promise used to return the result, which is the real-time downlink data traffic of all NICs in bytes.| 373 374**Error codes** 375 376For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 377 378| ID| Error Message | 379| --------- | -------------------------------------------- | 380| 2100002 | Failed to connect to the service. | 381| 2100003 | System internal error. | 382| 2103005 | Failed to read the system map. | 383| 2103011 | Failed to create a system map. | 384 385**Example** 386 387```js 388import { statistics } from '@kit.NetworkKit'; 389 390statistics.getAllRxBytes().then((stats: number) => { 391 console.log(JSON.stringify(stats)); 392}); 393``` 394 395## statistics.getAllTxBytes<sup>10+</sup> 396 397getAllTxBytes(callback: AsyncCallback\<number>): void; 398 399Obtains the real-time uplink data traffic of all NICs. This API uses an asynchronous callback to return the result. 400 401**System capability**: SystemCapability.Communication.NetManager.Core 402 403**Parameters** 404 405| Name | Type | Mandatory| Description | 406| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 407| callback | AsyncCallback\<number> | 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. | 408 409**Error codes** 410 411For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 412 413| ID| Error Message | 414| --------- | -------------------------------------------- | 415| 2100002 | Failed to connect to the service. | 416| 2100003 | System internal error. | 417| 2103005 | Failed to read the system map. | 418| 2103011 | Failed to create a system map. | 419 420**Example** 421 422```js 423import { BusinessError } from '@kit.BasicServicesKit'; 424import { statistics } from '@kit.NetworkKit'; 425 426statistics.getAllTxBytes((error: BusinessError, stats: number) => { 427 console.log(JSON.stringify(error)); 428 console.log(JSON.stringify(stats)); 429}); 430``` 431 432## statistics.getAllTxBytes<sup>10+</sup> 433 434getAllTxBytes(): Promise\<number>; 435 436Obtains the real-time uplink data traffic of all NICs. This API uses a promise to return the result. 437 438**System capability**: SystemCapability.Communication.NetManager.Core 439 440**Return value** 441| Type| Description| 442| -------- | -------- | 443| Promise\<number> | Promise used to return the result, which is the real-time uplink data traffic of all NICs in bytes.| 444 445**Error codes** 446 447For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 448 449| ID| Error Message | 450| --------- | -------------------------------------------- | 451| 2100002 | Failed to connect to the service. | 452| 2100003 | System internal error. | 453| 2103005 | Failed to read the system map. | 454| 2103011 | Failed to create a system map. | 455 456**Example** 457 458```js 459import { statistics } from '@kit.NetworkKit'; 460 461statistics.getAllTxBytes().then((stats: number) => { 462 console.log(JSON.stringify(stats)); 463}); 464``` 465 466## statistics.getUidRxBytes<sup>10+</sup> 467 468getUidRxBytes(uid: number, callback: AsyncCallback\<number>): void; 469 470Obtains the real-time downlink data traffic of the specified application. This API uses an asynchronous callback to return the result. 471 472**System capability**: SystemCapability.Communication.NetManager.Core 473 474**Parameters** 475 476| Name | Type | Mandatory| Description | 477| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 478| uid | number | Yes | Application UID. | 479| callback | AsyncCallback\<number> | 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. | 480 481**Error codes** 482 483For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 484 485| ID| Error Message | 486| --------- | -------------------------------------------- | 487| 401 | Parameter error. | 488| 2100002 | Failed to connect to the service. | 489| 2100003 | System internal error. | 490| 2103005 | Failed to read the system map. | 491| 2103011 | Failed to create a system map. | 492 493**Example** 494 495```js 496import { BusinessError } from '@kit.BasicServicesKit'; 497import { statistics } from '@kit.NetworkKit'; 498 499statistics.getUidRxBytes(20010038, (error: BusinessError, stats: number) => { 500 console.log(JSON.stringify(error)); 501 console.log(JSON.stringify(stats)); 502}); 503``` 504 505## statistics.getUidRxBytes<sup>10+</sup> 506 507getUidRxBytes(uid: number): Promise\<number>; 508 509Obtains the real-time downlink data traffic of the specified application. This API uses a promise to return the result. 510 511**System capability**: SystemCapability.Communication.NetManager.Core 512 513**Parameters** 514 515| Name| Type | Mandatory| Description | 516| ------ | ------ | ---- | -------------------- | 517| uid | number | Yes | Application UID.| 518 519**Return value** 520| Type| Description| 521| -------- | -------- | 522| Promise\<number> | Promise used to return the result, which is the real-time downlink data traffic of the application in bytes.| 523 524**Error codes** 525 526For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 527 528| ID| Error Message | 529| --------- | -------------------------------------------- | 530| 401 | Parameter error. | 531| 2100002 | Failed to connect to the service. | 532| 2100003 | System internal error. | 533| 2103005 | Failed to read the system map. | 534| 2103011 | Failed to create a system map. | 535 536**Example** 537 538```js 539import { statistics } from '@kit.NetworkKit'; 540 541statistics.getUidRxBytes(20010038).then((stats: number) => { 542 console.log(JSON.stringify(stats)); 543}); 544``` 545 546## statistics.getUidTxBytes<sup>10+</sup> 547 548getUidTxBytes(uid: number, callback: AsyncCallback\<number>): void; 549 550Obtains the real-time uplink data traffic of the specified application. This API uses an asynchronous callback to return the result. 551 552**System capability**: SystemCapability.Communication.NetManager.Core 553 554**Parameters** 555 556| Name | Type | Mandatory| Description | 557| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- | 558| uid | number | Yes | Application UID. | 559| callback | AsyncCallback\<number> | 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. | 560 561**Error codes** 562 563For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 564 565| ID| Error Message | 566| --------- | -------------------------------------------- | 567| 401 | Parameter error. | 568| 2100002 | Failed to connect to the service. | 569| 2100003 | System internal error. | 570| 2103005 | Failed to read the system map. | 571| 2103011 | Failed to create a system map. | 572 573**Example** 574 575```js 576import { BusinessError } from '@kit.BasicServicesKit'; 577import { statistics } from '@kit.NetworkKit'; 578 579statistics.getUidTxBytes(20010038, (error: BusinessError, stats: number) => { 580 console.log(JSON.stringify(error)); 581 console.log(JSON.stringify(stats)); 582}); 583``` 584 585## statistics.getUidTxBytes<sup>10+</sup> 586 587getUidTxBytes(uid: number): Promise\<number>; 588 589Obtains the real-time uplink data traffic of the specified application. This API uses a promise to return the result. 590 591**System capability**: SystemCapability.Communication.NetManager.Core 592 593**Parameters** 594 595| Name| Type | Mandatory| Description | 596| ------ | ------ | ---- | -------------------- | 597| uid | number | Yes | Application UID.| 598 599**Return value** 600| Type| Description| 601| -------- | -------- | 602| Promise\<number> | Promise used to return the result, which is the real-time uplink data traffic of the application in bytes.| 603 604**Error codes** 605 606For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 607 608| ID| Error Message | 609| --------- | -------------------------------------------- | 610| 401 | Parameter error. | 611| 2100002 | Failed to connect to the service. | 612| 2100003 | System internal error. | 613| 2103005 | Failed to read the system map. | 614| 2103011 | Failed to create a system map. | 615 616**Example** 617 618```js 619import { statistics } from '@kit.NetworkKit'; 620 621statistics.getUidTxBytes(20010038).then((stats: number) => { 622 console.log(JSON.stringify(stats)); 623}); 624``` 625 626 627## statistics.getSockfdRxBytes<sup>11+</sup> 628 629getSockfdRxBytes(sockfd: number, callback: AsyncCallback\<number\>): void; 630 631Obtains the downlink data traffic (in bytes) of the specified socket. This API uses an asynchronous callback to return the result. 632 633**System capability**: SystemCapability.Communication.NetManager.Core 634 635**Parameters** 636 637| Name | Type | Mandatory| Description | 638| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 639| sockfd | number | Yes | FD of the socket. | 640| callback | AsyncCallback\<number> | Yes | Callback used to return the result. Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the downlink data traffic of the socket. Otherwise, **error** is an error object.| 641 642**Error codes** 643 644For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 645 646| ID| Error Message | 647| --------- | -------------------------------------------- | 648| 401 | Parameter error. | 649| 2100001 | Invalid parameter value. | 650| 2100002 | Failed to connect to the service. | 651| 2100003 | System internal error. | 652 653**Example** 654 655```js 656import { BusinessError } from '@kit.BasicServicesKit'; 657import { statistics } from '@kit.NetworkKit'; 658 659let sockfd = 50; // FD of the socket you created. 660statistics.getSockfdRxBytes(sockfd, (error: BusinessError, stats: number) => { 661 console.log(JSON.stringify(error)); 662 console.log(JSON.stringify(stats)); 663}); 664``` 665 666## statistics.getSockfdRxBytes<sup>11+</sup> 667 668getSockfdRxBytes(sockfd: number): Promise\<number\>; 669 670Obtains the downlink data traffic (in bytes) of the specified socket. This API uses a promise to return the result. 671 672**System capability**: SystemCapability.Communication.NetManager.Core 673 674**Parameters** 675 676| Name| Type | Mandatory| Description | 677| ------ | ------ | ---- | ---------------------------------------- | 678| sockfd | number | Yes | FD of the socket.| 679 680**Return value** 681 682| Type | Description | 683| ---------------- | ------------------------------------------------------------ | 684| Promise\<number> | Promise used to return the result.| 685 686**Error codes** 687 688For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 689 690| ID| Error Message | 691| --------- | -------------------------------------------- | 692| 401 | Parameter error. | 693| 2100001 | Invalid parameter value. | 694| 2100002 | Failed to connect to the service. | 695| 2100003 | System internal error. | 696 697**Example** 698 699```js 700import { BusinessError } from '@kit.BasicServicesKit'; 701import { statistics } from '@kit.NetworkKit'; 702 703let sockfd = 50; // FD of the socket you created. 704statistics.getSockfdRxBytes(sockfd).then((stats: number) => { 705 console.log(JSON.stringify(stats)); 706}).catch((err: BusinessError) => { 707 console.error(JSON.stringify(err)); 708}); 709``` 710 711## statistics.getSockfdTxBytes<sup>11+</sup> 712 713getSockfdTxBytes(sockfd: number, callback: AsyncCallback\<number\>): void; 714 715Obtains the uplink data traffic (in bytes) of the specified socket. This API uses an asynchronous callback to return the result. 716 717**System capability**: SystemCapability.Communication.NetManager.Core 718 719**Parameters** 720 721| Name | Type | Mandatory| Description | 722| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 723| sockfd | number | Yes | FD of the socket. | 724| callback | AsyncCallback\<number> | Yes | Callback used to return the result. Callback used to return the result. If the operation is successful, **error** is **undefined** and **stats** is the uplink data traffic of the socket. Otherwise, **error** is an error object.| 725 726**Error codes** 727 728For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 729 730| ID| Error Message | 731| --------- | -------------------------------------------- | 732| 401 | Parameter error. | 733| 2100001 | Invalid parameter value. | 734| 2100002 | Failed to connect to the service. | 735| 2100003 | System internal error. | 736 737**Example** 738 739```js 740import { BusinessError } from '@kit.BasicServicesKit'; 741import { statistics } from '@kit.NetworkKit'; 742 743let sockfd = 50; // FD of the socket you created. 744statistics.getSockfdTxBytes(sockfd, (error: BusinessError, stats: number) => { 745 console.log(JSON.stringify(error)); 746 console.log(JSON.stringify(stats)); 747}); 748``` 749 750## statistics.getSockfdTxBytes<sup>11+</sup> 751 752getSockfdTxBytes(sockfd: number): Promise\<number\>; 753 754Obtains the uplink data traffic (in bytes) of the specified socket. This API uses a promise to return the result. 755 756**System capability**: SystemCapability.Communication.NetManager.Core 757 758**Parameters** 759 760| Name| Type | Mandatory| Description | 761| ------ | ------ | ---- | ---------------------------------------- | 762| sockfd | number | Yes | FD of the socket.| 763 764**Return value** 765 766| Type | Description | 767| ---------------- | ------------------------------------------------------------ | 768| Promise\<number> | Promise used to return the result.| 769 770**Error codes** 771 772For details about the error codes, see [Traffic Management Error Codes](errorcode-net-statistics.md). 773 774| ID| Error Message | 775| --------- | -------------------------------------------- | 776| 401 | Parameter error. | 777| 2100001 | Invalid parameter value. | 778| 2100002 | Failed to connect to the service. | 779| 2100003 | System internal error. | 780 781**Example** 782 783```js 784import { BusinessError } from '@kit.BasicServicesKit'; 785import { statistics } from '@kit.NetworkKit'; 786 787let sockfd = 50; // FD of the socket you created. 788statistics.getSockfdTxBytes(sockfd).then((stats: number) => { 789 console.log(JSON.stringify(stats)); 790}).catch((err: BusinessError) => { 791 console.error(JSON.stringify(err)); 792}); 793``` 794 795## NetBearType 796 797type NetBearType = connection.NetBearType 798 799Enumerates network types. 800 801**System capability**: SystemCapability.Communication.NetStack 802 803| Type | Description | 804| ---------------- | --------------------------- | 805| connection.NetBearType | Network type. | 806