• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.net.statistics (流量管理)
2
3流量管理模块提供获取指定网卡实时上行、下行流量等能力。
4
5> **说明:**
6>
7> 本模块首批接口从 API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import { statistics } from '@kit.NetworkKit';
13```
14
15## statistics.getIfaceRxBytes<sup>10+</sup>
16
17getIfaceRxBytes(nic: string, callback: AsyncCallback\<number>): void;
18
19获取指定网卡实时下行流量,使用 callback 方式作为异步方法。
20
21**系统能力**:SystemCapability.Communication.NetManager.Core
22
23**参数:**
24
25| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
26| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
27| nic      | string                 | 是   | 指定查询的网卡名。                                                                                                      |
28| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取网卡实时下行流量时,error 为 undefined,stats 为获取到的网卡实时下行流量(单位:字节);否则为错误对象。    |
29
30**错误码:**
31
32以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
33
34| 错误码 ID | 错误信息                                     |
35| --------- | -------------------------------------------- |
36| 401       | Parameter error.                             |
37| 2100002   | Failed to connect to the service.            |
38| 2100003   | System internal error.                       |
39| 2103005   | Failed to read the system map.               |
40| 2103011   | Failed to create a system map.               |
41| 2103012   | Failed to obtain the NIC name.               |
42
43**示例:**
44
45```js
46import { BusinessError } from '@kit.BasicServicesKit';
47import { statistics } from '@kit.NetworkKit';
48
49statistics.getIfaceRxBytes("wlan0", (error: BusinessError, stats: number) => {
50  console.log(JSON.stringify(error));
51  console.log(JSON.stringify(stats));
52});
53```
54
55## statistics.getIfaceRxBytes<sup>10+</sup>
56
57getIfaceRxBytes(nic: string): Promise\<number>;
58
59获取指定网卡实时下行流量,使用 Promise 方式作为异步方法。
60
61**系统能力**:SystemCapability.Communication.NetManager.Core
62
63**参数:**
64
65| 参数名 | 类型   | 必填 | 说明               |
66| ------ | ------ | ---- | ------------------ |
67| nic    | string | 是   | 指定查询的网卡名。 |
68
69**返回值:**
70| 类型 | 说明 |
71| -------- | -------- |
72| Promise\<number> | 以 Promise 形式返回获取结果。返回网卡实时下行流量(单位:字节)。 |
73
74**错误码:**
75
76以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
77
78| 错误码 ID | 错误信息                                     |
79| --------- | -------------------------------------------- |
80| 401       | Parameter error.                             |
81| 2100002   | Failed to connect to the service.            |
82| 2100003   | System internal error.                       |
83| 2103005   | Failed to read the system map.               |
84| 2103011   | Failed to create a system map.               |
85| 2103012   | Failed to obtain the NIC name.               |
86
87**示例:**
88
89```js
90import { statistics } from '@kit.NetworkKit';
91
92statistics.getIfaceRxBytes("wlan0").then((stats: number) => {
93  console.log(JSON.stringify(stats));
94});
95```
96
97## statistics.getIfaceTxBytes<sup>10+</sup>
98
99getIfaceTxBytes(nic: string, callback: AsyncCallback\<number>): void;
100
101获取指定网卡实时上行流量,使用 callback 方式作为异步方法。
102
103**系统能力**:SystemCapability.Communication.NetManager.Core
104
105**参数:**
106
107| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
108| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
109| nic      | string                 | 是   | 指定查询的网卡名。                                                                                                      |
110| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取网卡实时上行流量时,error 为 undefined,stats 为获取到的网卡实时上行流量(单位:字节);否则为错误对象。    |
111
112**错误码:**
113
114以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
115
116| 错误码 ID | 错误信息                                     |
117| --------- | -------------------------------------------- |
118| 401       | Parameter error.                             |
119| 2100002   | Failed to connect to the service.            |
120| 2100003   | System internal error.                       |
121| 2103005   | Failed to read the system map.               |
122| 2103011   | Failed to create a system map.               |
123| 2103012   | Failed to obtain the NIC name.               |
124
125**示例:**
126
127```js
128import { BusinessError } from '@kit.BasicServicesKit';
129import { statistics } from '@kit.NetworkKit';
130
131statistics.getIfaceTxBytes("wlan0", (error: BusinessError, stats: number) => {
132  console.log(JSON.stringify(error));
133  console.log(JSON.stringify(stats));
134});
135```
136
137## statistics.getIfaceTxBytes<sup>10+</sup>
138
139getIfaceTxBytes(nic: string): Promise\<number>;
140
141获取指定网卡实时上行流量,使用 Promise 方式作为异步方法。
142
143**系统能力**:SystemCapability.Communication.NetManager.Core
144
145**参数:**
146
147| 参数名 | 类型   | 必填 | 说明               |
148| ------ | ------ | ---- | ------------------ |
149| nic    | string | 是   | 指定查询的网卡名。 |
150
151**返回值:**
152| 类型 | 说明 |
153| -------- | -------- |
154| Promise\<number> | 以 Promise 形式返回获取结果。返回网卡实时上行流量(单位:字节)。 |
155
156**错误码:**
157
158以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
159
160| 错误码 ID | 错误信息                                     |
161| --------- | -------------------------------------------- |
162| 401       | Parameter error.                             |
163| 2100002   | Failed to connect to the service.            |
164| 2100003   | System internal error.                       |
165| 2103005   | Failed to read the system map.               |
166| 2103011   | Failed to create a system map.               |
167| 2103012   | Failed to obtain the NIC name.               |
168
169**示例:**
170
171```js
172import { statistics } from '@kit.NetworkKit';
173
174statistics.getIfaceTxBytes("wlan0").then((stats: number) => {
175  console.log(JSON.stringify(stats));
176});
177```
178
179## statistics.getCellularRxBytes<sup>10+</sup>
180
181getCellularRxBytes(callback: AsyncCallback\<number>): void;
182
183获取蜂窝实时下行流量,使用 callback 方式作为异步方法。
184
185**系统能力**:SystemCapability.Communication.NetManager.Core
186
187**参数:**
188
189| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
190| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
191| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取蜂窝实时下行流量时,error 为 undefined,stats 为获取到的蜂窝实时下行流量(单位:字节);否则为错误对象。    |
192
193**错误码:**
194
195以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
196
197| 错误码 ID | 错误信息                                     |
198| --------- | -------------------------------------------- |
199| 2100002   | Failed to connect to the service.            |
200| 2100003   | System internal error.                       |
201| 2103005   | Failed to read the system map.               |
202| 2103011   | Failed to create a system map.               |
203| 2103012   | Failed to obtain the NIC name.               |
204
205**示例:**
206
207```js
208import { BusinessError } from '@kit.BasicServicesKit';
209import { statistics } from '@kit.NetworkKit';
210
211statistics.getCellularRxBytes((error: BusinessError, stats: number) => {
212  console.log(JSON.stringify(error));
213  console.log(JSON.stringify(stats));
214});
215```
216
217## statistics.getCellularRxBytes<sup>10+</sup>
218
219getCellularRxBytes(): Promise\<number>;
220
221获取蜂窝实时下行流量,使用 Promise 方式作为异步方法。
222
223**系统能力**:SystemCapability.Communication.NetManager.Core
224
225**返回值:**
226| 类型 | 说明 |
227| -------- | -------- |
228| Promise\<number> | 以 Promise 形式返回获取结果。返回蜂窝实时下行流量(单位:字节)。 |
229
230**错误码:**
231
232以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
233
234| 错误码 ID | 错误信息                                     |
235| --------- | -------------------------------------------- |
236| 2100002   | Failed to connect to the service.            |
237| 2100003   | System internal error.                       |
238| 2103005   | Failed to read the system map.               |
239| 2103011   | Failed to create a system map.               |
240| 2103012   | Failed to obtain the NIC name.               |
241
242**示例:**
243
244```js
245import { statistics } from '@kit.NetworkKit';
246
247statistics.getCellularRxBytes().then((stats: number) => {
248  console.log(JSON.stringify(stats));
249});
250```
251
252## statistics.getCellularTxBytes<sup>10+</sup>
253
254getCellularTxBytes(callback: AsyncCallback\<number>): void;
255
256获取蜂窝实时上行流量,使用 callback 方式作为异步方法。
257
258**系统能力**:SystemCapability.Communication.NetManager.Core
259
260**参数:**
261
262| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
263| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
264| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取蜂窝实时上行流量时,error 为 undefined,stats 为获取到的蜂窝实时上行流量(单位:字节);否则为错误对象。    |
265
266**错误码:**
267
268以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
269
270| 错误码 ID | 错误信息                                     |
271| --------- | -------------------------------------------- |
272| 2100002   | Failed to connect to the service.            |
273| 2100003   | System internal error.                       |
274| 2103005   | Failed to read the system map.               |
275| 2103011   | Failed to create a system map.               |
276| 2103012   | Failed to obtain the NIC name.               |
277
278**示例:**
279
280```js
281import { BusinessError } from '@kit.BasicServicesKit';
282import { statistics } from '@kit.NetworkKit';
283
284statistics.getCellularTxBytes((error: BusinessError, stats: number) => {
285  console.log(JSON.stringify(error));
286  console.log(JSON.stringify(stats));
287});
288```
289
290## statistics.getCellularTxBytes<sup>10+</sup>
291
292getCellularTxBytes(): Promise\<number>;
293
294获取蜂窝实时上行流量,使用 Promise 方式作为异步方法。
295
296**系统能力**:SystemCapability.Communication.NetManager.Core
297
298**返回值:**
299| 类型 | 说明 |
300| -------- | -------- |
301| Promise\<number> | 以 Promise 形式返回获取结果。返回蜂窝实时上行流量(单位:字节)。 |
302
303**错误码:**
304
305以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
306
307| 错误码 ID | 错误信息                                     |
308| --------- | -------------------------------------------- |
309| 2100002   | Failed to connect to the service.            |
310| 2100003   | System internal error.                       |
311| 2103005   | Failed to read the system map.               |
312| 2103011   | Failed to create a system map.               |
313| 2103012   | Failed to obtain the NIC name.               |
314
315**示例:**
316
317```js
318import { statistics } from '@kit.NetworkKit';
319
320statistics.getCellularTxBytes().then((stats: number) => {
321  console.log(JSON.stringify(stats));
322});
323```
324
325## statistics.getAllRxBytes<sup>10+</sup>
326
327getAllRxBytes(callback: AsyncCallback\<number>): void;
328
329获取所有网卡实时下行流量,使用 callback 方式作为异步方法。
330
331**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
332
333**系统能力**:SystemCapability.Communication.NetManager.Core
334
335**参数:**
336
337| 参数名   | 类型                   | 必填 | 说明                                                                                                                          |
338| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
339| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取所有网卡实时下行流量,error 为 undefined,stats 为获取到的所有网卡实时下行流量(单位:字节);否则为错误对象。    |
340
341**错误码:**
342
343以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
344
345| 错误码 ID | 错误信息                                     |
346| --------- | -------------------------------------------- |
347| 2100002   | Failed to connect to the service. |
348| 2100003   | System internal error.                       |
349| 2103005   | Failed to read the system map.               |
350| 2103011   | Failed to create a system map.               |
351
352**示例:**
353
354```js
355import { statistics } from '@kit.NetworkKit';
356import { BusinessError } from '@kit.BasicServicesKit';
357
358statistics.getAllRxBytes((error: BusinessError, stats: number) => {
359  console.log(JSON.stringify(error));
360  console.log(JSON.stringify(stats));
361});
362```
363
364## statistics.getAllRxBytes<sup>10+</sup>
365
366getAllRxBytes(): Promise\<number>;
367
368获取所有网卡实时下行流量,使用 Promise 方式作为异步方法。
369
370**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
371
372**系统能力**:SystemCapability.Communication.NetManager.Core
373
374**返回值:**
375| 类型 | 说明 |
376| -------- | -------- |
377| Promise\<number> | 以 Promise 形式返回获取结果。返回所有网卡实时下行流量(单位:字节)。 |
378
379**错误码:**
380
381以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
382
383| 错误码 ID | 错误信息                                     |
384| --------- | -------------------------------------------- |
385| 2100002   | Failed to connect to the service.            |
386| 2100003   | System internal error.                       |
387| 2103005   | Failed to read the system map.               |
388| 2103011   | Failed to create a system map.               |
389
390**示例:**
391
392```js
393import { statistics } from '@kit.NetworkKit';
394
395statistics.getAllRxBytes().then((stats: number) => {
396  console.log(JSON.stringify(stats));
397});
398```
399
400## statistics.getAllTxBytes<sup>10+</sup>
401
402getAllTxBytes(callback: AsyncCallback\<number>): void;
403
404获取所有网卡实时上行流量,使用 callback 方式作为异步方法。
405
406**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
407
408**系统能力**:SystemCapability.Communication.NetManager.Core
409
410**参数:**
411
412| 参数名   | 类型                   | 必填 | 说明                                                                                                                          |
413| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
414| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取所有网卡实时上行流量,error 为 undefined,stats 为获取到的所有网卡实时上行流量(单位:字节);否则为错误对象。    |
415
416**错误码:**
417
418以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
419
420| 错误码 ID | 错误信息                                     |
421| --------- | -------------------------------------------- |
422| 2100002   | Failed to connect to the service.            |
423| 2100003   | System internal error.                       |
424| 2103005   | Failed to read the system map.               |
425| 2103011   | Failed to create a system map.               |
426
427**示例:**
428
429```js
430import { BusinessError } from '@kit.BasicServicesKit';
431import { statistics } from '@kit.NetworkKit';
432
433statistics.getAllTxBytes((error: BusinessError, stats: number) => {
434  console.log(JSON.stringify(error));
435  console.log(JSON.stringify(stats));
436});
437```
438
439## statistics.getAllTxBytes<sup>10+</sup>
440
441getAllTxBytes(): Promise\<number>;
442
443获取所有网卡实时上行流量,使用 Promise 方式作为异步方法。
444
445**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
446
447**系统能力**:SystemCapability.Communication.NetManager.Core
448
449**返回值:**
450| 类型 | 说明 |
451| -------- | -------- |
452| Promise\<number> | 以 Promise 形式返回获取结果。返回所有网卡实时上行流量(单位:字节)。 |
453
454**错误码:**
455
456以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
457
458| 错误码 ID | 错误信息                                     |
459| --------- | -------------------------------------------- |
460| 2100002   | Failed to connect to the service.            |
461| 2100003   | System internal error.                       |
462| 2103005   | Failed to read the system map.               |
463| 2103011   | Failed to create a system map.               |
464
465**示例:**
466
467```js
468import { statistics } from '@kit.NetworkKit';
469
470statistics.getAllTxBytes().then((stats: number) => {
471  console.log(JSON.stringify(stats));
472});
473```
474
475## statistics.getUidRxBytes<sup>10+</sup>
476
477getUidRxBytes(uid: number, callback: AsyncCallback\<number>): void;
478
479获取指定应用实时下行流量,使用 callback 方式作为异步方法。
480
481**系统能力**:SystemCapability.Communication.NetManager.Core
482
483**参数:**
484
485| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
486| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
487| uid      | number                 | 是   | 指定查询的应用 uid。                                                                                                    |
488| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取应用实时下行流量时,error 为 undefined,stats 为获取到的应用实时下行流量(单位:字节);否则为错误对象。    |
489
490**错误码:**
491
492以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
493
494| 错误码 ID | 错误信息                                     |
495| --------- | -------------------------------------------- |
496| 401       | Parameter error.                             |
497| 2100002   | Failed to connect to the service.            |
498| 2100003   | System internal error.                       |
499| 2103005   | Failed to read the system map.               |
500| 2103011   | Failed to create a system map.               |
501
502**示例:**
503
504```js
505import { BusinessError } from '@kit.BasicServicesKit';
506import { statistics } from '@kit.NetworkKit';
507
508statistics.getUidRxBytes(20010038, (error: BusinessError, stats: number) => {
509  console.log(JSON.stringify(error));
510  console.log(JSON.stringify(stats));
511});
512```
513
514## statistics.getUidRxBytes<sup>10+</sup>
515
516getUidRxBytes(uid: number): Promise\<number>;
517
518获取指定应用实时下行流量,使用 Promise 方式作为异步方法。
519
520**系统能力**:SystemCapability.Communication.NetManager.Core
521
522**参数:**
523
524| 参数名 | 类型   | 必填 | 说明                 |
525| ------ | ------ | ---- | -------------------- |
526| uid    | number | 是   | 指定查询的应用 uid。 |
527
528**返回值:**
529| 类型 | 说明 |
530| -------- | -------- |
531| Promise\<number> | 以 Promise 形式返回获取结果。返回指定应用实时下行流量(单位:字节)。 |
532
533**错误码:**
534
535以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
536
537| 错误码 ID | 错误信息                                     |
538| --------- | -------------------------------------------- |
539| 401       | Parameter error.                             |
540| 2100002   | Failed to connect to the service.            |
541| 2100003   | System internal error.                       |
542| 2103005   | Failed to read the system map.               |
543| 2103011   | Failed to create a system map.               |
544
545**示例:**
546
547```js
548import { statistics } from '@kit.NetworkKit';
549
550statistics.getUidRxBytes(20010038).then((stats: number) => {
551  console.log(JSON.stringify(stats));
552});
553```
554
555## statistics.getUidTxBytes<sup>10+</sup>
556
557getUidTxBytes(uid: number, callback: AsyncCallback\<number>): void;
558
559获取指定应用实时上行流量,使用 callback 方式作为异步方法。
560
561**系统能力**:SystemCapability.Communication.NetManager.Core
562
563**参数:**
564
565| 参数名   | 类型                   | 必填 | 说明                                                                                                                    |
566| -------- | ---------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------- |
567| uid      | number                 | 是   | 指定查询的应用 uid。                                                                                                    |
568| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取应用实时上行流量时,error 为 undefined,stats 为获取到的应用实时上行流量(单位:字节);否则为错误对象。    |
569
570**错误码:**
571
572以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
573
574| 错误码 ID | 错误信息                                     |
575| --------- | -------------------------------------------- |
576| 401       | Parameter error.                             |
577| 2100002   | Failed to connect to the service.            |
578| 2100003   | System internal error.                       |
579| 2103005   | Failed to read the system map.               |
580| 2103011   | Failed to create a system map.               |
581
582**示例:**
583
584```js
585import { BusinessError } from '@kit.BasicServicesKit';
586import { statistics } from '@kit.NetworkKit';
587
588statistics.getUidTxBytes(20010038, (error: BusinessError, stats: number) => {
589  console.log(JSON.stringify(error));
590  console.log(JSON.stringify(stats));
591});
592```
593
594## statistics.getUidTxBytes<sup>10+</sup>
595
596getUidTxBytes(uid: number): Promise\<number>;
597
598获取指定应用实时上行流量,使用 Promise 方式作为异步方法。
599
600**系统能力**:SystemCapability.Communication.NetManager.Core
601
602**参数:**
603
604| 参数名 | 类型   | 必填 | 说明                 |
605| ------ | ------ | ---- | -------------------- |
606| uid    | number | 是   | 指定查询的应用 uid。 |
607
608**返回值:**
609| 类型 | 说明 |
610| -------- | -------- |
611| Promise\<number> | 以 Promise 形式返回获取结果。返回指定应用实时上行流量(单位:字节)。 |
612
613**错误码:**
614
615以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
616
617| 错误码 ID | 错误信息                                     |
618| --------- | -------------------------------------------- |
619| 401       | Parameter error.                             |
620| 2100002   | Failed to connect to the service.            |
621| 2100003   | System internal error.                       |
622| 2103005   | Failed to read the system map.               |
623| 2103011   | Failed to create a system map.               |
624
625**示例:**
626
627```js
628import { statistics } from '@kit.NetworkKit';
629
630statistics.getUidTxBytes(20010038).then((stats: number) => {
631  console.log(JSON.stringify(stats));
632});
633```
634
635
636## statistics.getSockfdRxBytes<sup>11+</sup>
637
638getSockfdRxBytes(sockfd: number, callback: AsyncCallback\<number\>): void;
639
640获取指定socket的下行流量信息,使用 callback 方式作为异步方法。
641
642**系统能力**:SystemCapability.Communication.NetManager.Core
643
644**参数:**
645
646| 参数名   | 类型                   | 必填 | 说明                                                         |
647| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
648| sockfd   | number                 | 是   | 指定查询的socket的fd(file description)。                     |
649| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取socket的下行流量时,error 为 undefined,stats 为获取到的该socket的实时下行流量(单位:字节);否则为错误对象。 |
650
651**错误码:**
652
653以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
654
655| 错误码 ID | 错误信息                                     |
656| --------- | -------------------------------------------- |
657| 401       | Parameter error.                             |
658| 2100001   | Invalid parameter value.                     |
659| 2100002   | Failed to connect to the service.            |
660| 2100003   | System internal error.                       |
661
662**示例:**
663
664```js
665import { BusinessError } from '@kit.BasicServicesKit';
666import { statistics } from '@kit.NetworkKit';
667
668let sockfd = 50; // 实际开发中需要先根据自己创建的socket获取到
669statistics.getSockfdRxBytes(sockfd, (error: BusinessError, stats: number) => {
670  console.log(JSON.stringify(error));
671  console.log(JSON.stringify(stats));
672});
673```
674
675## statistics.getSockfdRxBytes<sup>11+</sup>
676
677getSockfdRxBytes(sockfd: number): Promise\<number\>;
678
679获取指定socket的下行流量信息,使用 Promise 方式作为异步方法。
680
681**系统能力**:SystemCapability.Communication.NetManager.Core
682
683**参数:**
684
685| 参数名 | 类型   | 必填 | 说明                                     |
686| ------ | ------ | ---- | ---------------------------------------- |
687| sockfd | number | 是   | 指定查询的socket的fd(file description)。 |
688
689**返回值:**
690
691| 类型             | 说明                                                         |
692| ---------------- | ------------------------------------------------------------ |
693| Promise\<number> | 以 Promise 形式返回获取结果,返回该socket的实时下行流量(单位:字节)。 |
694
695**错误码:**
696
697以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
698
699| 错误码 ID | 错误信息                                     |
700| --------- | -------------------------------------------- |
701| 401       | Parameter error.                             |
702| 2100001   | Invalid parameter value.                     |
703| 2100002   | Failed to connect to the service.            |
704| 2100003   | System internal error.                       |
705
706**示例:**
707
708```js
709import { BusinessError } from '@kit.BasicServicesKit';
710import { statistics } from '@kit.NetworkKit';
711
712let sockfd = 50; // 实际开发中需要先根据自己创建的socket获取到
713statistics.getSockfdRxBytes(sockfd).then((stats: number) => {
714  console.log(JSON.stringify(stats));
715}).catch((err: BusinessError) => {
716  console.error(JSON.stringify(err));
717});
718```
719
720## statistics.getSockfdTxBytes<sup>11+</sup>
721
722getSockfdTxBytes(sockfd: number, callback: AsyncCallback\<number\>): void;
723
724获取指定socket的上行流量信息,使用 callback 方式作为异步方法。
725
726**系统能力**:SystemCapability.Communication.NetManager.Core
727
728**参数:**
729
730| 参数名   | 类型                   | 必填 | 说明                                                         |
731| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
732| sockfd   | number                 | 是   | 指定查询的socket的fd(file description)。                     |
733| callback | AsyncCallback\<number> | 是   | 回调函数。当成功获取socket的上行流量时,error 为 undefined,stats 为获取到的该socket的实时上行流量(单位:字节);否则为错误对象。 |
734
735**错误码:**
736
737以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
738
739| 错误码 ID | 错误信息                                     |
740| --------- | -------------------------------------------- |
741| 401       | Parameter error.                             |
742| 2100001   | Invalid parameter value.                     |
743| 2100002   | Failed to connect to the service.            |
744| 2100003   | System internal error.                       |
745
746**示例:**
747
748```js
749import { BusinessError } from '@kit.BasicServicesKit';
750import { statistics } from '@kit.NetworkKit';
751
752let sockfd = 50; // 实际开发中需要先根据自己创建的socket获取到
753statistics.getSockfdTxBytes(sockfd, (error: BusinessError, stats: number) => {
754  console.log(JSON.stringify(error));
755  console.log(JSON.stringify(stats));
756});
757```
758
759## statistics.getSockfdTxBytes<sup>11+</sup>
760
761getSockfdTxBytes(sockfd: number): Promise\<number\>;
762
763获取指定socket的上行流量信息,使用 Promise 方式作为异步方法。
764
765**系统能力**:SystemCapability.Communication.NetManager.Core
766
767**参数:**
768
769| 参数名 | 类型   | 必填 | 说明                                     |
770| ------ | ------ | ---- | ---------------------------------------- |
771| sockfd | number | 是   | 指定查询的socket的fd(file description)。 |
772
773**返回值:**
774
775| 类型             | 说明                                                         |
776| ---------------- | ------------------------------------------------------------ |
777| Promise\<number> | 以 Promise 形式返回获取结果,返回该socket的实时上行流量(单位:字节)。 |
778
779**错误码:**
780
781以下错误码的详细介绍参见[statistics 错误码](errorcode-net-statistics.md)。
782
783| 错误码 ID | 错误信息                                     |
784| --------- | -------------------------------------------- |
785| 401       | Parameter error.                             |
786| 2100001   | Invalid parameter value.                     |
787| 2100002   | Failed to connect to the service.            |
788| 2100003   | System internal error.                       |
789
790**示例:**
791
792```js
793import { BusinessError } from '@kit.BasicServicesKit';
794import { statistics } from '@kit.NetworkKit';
795
796let sockfd = 50; // 实际开发中需要先根据自己创建的socket获取到
797statistics.getSockfdTxBytes(sockfd).then((stats: number) => {
798  console.log(JSON.stringify(stats));
799}).catch((err: BusinessError) => {
800  console.error(JSON.stringify(err));
801});
802```
803
804## NetBearType<sup>12+</sup>
805
806type NetBearType = connection.NetBearType
807
808网络类型。
809
810**系统能力**:SystemCapability.Communication.NetManager.Core
811
812|       类型       |            说明             |
813| ---------------- | --------------------------- |
814| [connection.NetBearType](js-apis-net-connection.md#netbeartype) | 枚举网络类型。    |
815