• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit NetworkKit
19 */
20
21import type { AsyncCallback, Callback, ErrorCallback } from './@ohos.base';
22import connection from "./@ohos.net.connection";
23import type cert from './@ohos.security.cert';
24
25/**
26 * Provides TCP and UDP Socket APIs.
27 * @namespace socket
28 * @syscap SystemCapability.Communication.NetStack
29 * @since 7
30 */
31/**
32 * Provides TCP and UDP Socket APIs.
33 * @namespace socket
34 * @syscap SystemCapability.Communication.NetStack
35 * @crossplatform
36 * @since 10
37 */
38declare namespace socket {
39  export import NetAddress = connection.NetAddress;
40  /**
41   * Deposit certificate
42   * @syscap SystemCapability.Communication.NetStack
43   * @since 9
44   */
45  /**
46   * Deposit certificate
47   * @typedef { cert.EncodingBlob }
48   * @syscap SystemCapability.Communication.NetStack
49   * @crossplatform
50   * @since 10
51   */
52  export type X509CertRawData = cert.EncodingBlob;
53
54  /**
55   * Creates a UDPSocket object.
56   * @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance.
57   * @syscap SystemCapability.Communication.NetStack
58   * @since 7
59   */
60  /**
61   * Creates a UDPSocket object.
62   * @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance.
63   * @syscap SystemCapability.Communication.NetStack
64   * @crossplatform
65   * @since 10
66   */
67  function constructUDPSocketInstance(): UDPSocket;
68
69  /**
70   * Creates a MulticastSocket object.
71   * @returns { MulticastSocket } the MulticastSocket of the constructMulticastSocketInstance.
72   * @syscap SystemCapability.Communication.NetStack
73   * @since 11
74   */
75  /**
76   * Creates a MulticastSocket object.
77   * @returns { MulticastSocket } the MulticastSocket of the constructMulticastSocketInstance.
78   * @syscap SystemCapability.Communication.NetStack
79   * @crossplatform
80   * @since 12
81   */
82  function constructMulticastSocketInstance(): MulticastSocket;
83
84  /**
85   * Creates a TCPSocket object.
86   * @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance.
87   * @syscap SystemCapability.Communication.NetStack
88   * @since 7
89   */
90  /**
91   * Creates a TCPSocket object.
92   * @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance.
93   * @syscap SystemCapability.Communication.NetStack
94   * @crossplatform
95   * @since 10
96   */
97  function constructTCPSocketInstance(): TCPSocket;
98
99  /**
100   * Creates a TLSSocket object.
101   * @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
102   * @syscap SystemCapability.Communication.NetStack
103   * @since 9
104   */
105  /**
106   * Creates a TLSSocket object.
107   * @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
108   * @syscap SystemCapability.Communication.NetStack
109   * @crossplatform
110   * @since 10
111   */
112  function constructTLSSocketInstance(): TLSSocket;
113
114  /**
115   * Creates a TLSSocket object with a TCPSocket object.
116   * @param { TCPSocket } tcpSocket - Parameter for creating a TLSSocket object.
117   * @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
118   * @throws { BusinessError } 401 - Parameter error.
119   * @throws { BusinessError } 2300002 - System internal error.
120   * @throws { BusinessError } 2303601 - Invalid socket FD.
121   * @throws { BusinessError } 2303602 - Socket is not connected.
122   * @syscap SystemCapability.Communication.NetStack
123   * @since 12
124   */
125  function constructTLSSocketInstance(tcpSocket: TCPSocket): TLSSocket;
126
127  /**
128   * Creates a TCPSocketServer object.
129   * @returns { TCPSocketServer } the TCPSocketServer of the constructTCPSocketServerInstance.
130   * @syscap SystemCapability.Communication.NetStack
131   * @since 10
132   */
133  function constructTCPSocketServerInstance(): TCPSocketServer;
134
135  /**
136   * Creates a TLSSocketServer object.
137   * @returns { TLSSocketServer } the TLSSocketServer of the constructTLSSocketServerInstance.
138   * @syscap SystemCapability.Communication.NetStack
139   * @since 10
140   */
141  function constructTLSSocketServerInstance(): TLSSocketServer;
142
143  /**
144   * Creates a LocalSocket object.
145   * @returns { LocalSocket } the LocalSocket of the constructLocalSocketInstance.
146   * @syscap SystemCapability.Communication.NetStack
147   * @since 11
148   */
149  /**
150   * Creates a LocalSocket object.
151   * @returns { LocalSocket } the LocalSocket of the constructLocalSocketInstance.
152   * @syscap SystemCapability.Communication.NetStack
153   * @crossplatform
154   * @since 12
155   */
156  function constructLocalSocketInstance(): LocalSocket;
157
158  /**
159   * Creates a LocalSocketServer object.
160   * @returns { LocalSocketServer } the LocalSocketServer of the constructLocalSocketServerInstance.
161   * @syscap SystemCapability.Communication.NetStack
162   * @since 11
163   */
164  /**
165   * Creates a LocalSocketServer object.
166   * @returns { LocalSocketServer } the LocalSocketServer of the constructLocalSocketServerInstance.
167   * @syscap SystemCapability.Communication.NetStack
168   * @crossplatform
169   * @since 12
170   */
171  function constructLocalSocketServerInstance(): LocalSocketServer;
172
173  /**
174   * Defines the parameters for sending data over the UDPSocket connection.
175   * @interface UDPSendOptions
176   * @syscap SystemCapability.Communication.NetStack
177   * @since 7
178   */
179  /**
180   * Defines the parameters for sending data over the UDPSocket connection.
181   * @interface UDPSendOptions
182   * @syscap SystemCapability.Communication.NetStack
183   * @crossplatform
184   * @since 10
185   */
186  export interface UDPSendOptions {
187    /**
188     * Data to send.
189     * @type {string | ArrayBuffer}
190     * @syscap SystemCapability.Communication.NetStack
191     * @since 7
192     */
193    /**
194     * Data to send.
195     * @type {string | ArrayBuffer}
196     * @syscap SystemCapability.Communication.NetStack
197     * @crossplatform
198     * @since 10
199     */
200    data: string | ArrayBuffer;
201
202    /**
203     * Destination address.
204     * @type {NetAddress}
205     * @syscap SystemCapability.Communication.NetStack
206     * @since 7
207     */
208    /**
209     * Destination address.
210     * @type {NetAddress}
211     * @syscap SystemCapability.Communication.NetStack
212     * @crossplatform
213     * @since 10
214     */
215    address: NetAddress;
216  }
217
218  /**
219   * @interface ExtraOptionsBase
220   * @syscap SystemCapability.Communication.NetStack
221   * @since 7
222   */
223  /**
224   * @interface ExtraOptionsBase
225   * @syscap SystemCapability.Communication.NetStack
226   * @crossplatform
227   * @since 10
228   */
229  export interface ExtraOptionsBase {
230    /**
231     * Size of the receive buffer, in MBS.
232     * @type {?number}
233     * @syscap SystemCapability.Communication.NetStack
234     * @since 7
235     */
236    /**
237     * Size of the receive buffer, in MBS.
238     * @type {?number}
239     * @syscap SystemCapability.Communication.NetStack
240     * @crossplatform
241     * @since 10
242     */
243    receiveBufferSize?: number;
244
245    /**
246     * Size of the send buffer, in MBS.
247     * @type {?number}
248     * @syscap SystemCapability.Communication.NetStack
249     * @since 7
250     */
251    /**
252     * Size of the send buffer, in MBS.
253     * @type {?number}
254     * @syscap SystemCapability.Communication.NetStack
255     * @crossplatform
256     * @since 10
257     */
258    sendBufferSize?: number;
259
260    /**
261     * Whether to reuse addresses. The default value is false.
262     * @type {?boolean}
263     * @syscap SystemCapability.Communication.NetStack
264     * @since 7
265     */
266    /**
267     * Whether to reuse addresses. The default value is false.
268     * @type {?boolean}
269     * @syscap SystemCapability.Communication.NetStack
270     * @crossplatform
271     * @since 10
272     */
273    reuseAddress?: boolean;
274
275    /**
276     * Timeout duration of the UDPSocket connection, in milliseconds.
277     * @type {?number}
278     * @syscap SystemCapability.Communication.NetStack
279     * @since 7
280     */
281    /**
282     * Timeout duration of the UDPSocket connection, in milliseconds.
283     * @type {?number}
284     * @syscap SystemCapability.Communication.NetStack
285     * @crossplatform
286     * @since 10
287     */
288    socketTimeout?: number;
289  }
290
291  /**
292   * Defines other properties of the UDPSocket connection.
293   * @interface UDPExtraOptions
294   * @syscap SystemCapability.Communication.NetStack
295   * @since 7
296   */
297  /**
298   * Defines other properties of the UDPSocket connection.
299   * @extends ExtraOptionsBase
300   * @interface UDPExtraOptions
301   * @syscap SystemCapability.Communication.NetStack
302   * @crossplatform
303   * @since 10
304   */
305  export interface UDPExtraOptions extends ExtraOptionsBase {
306    /**
307     * Whether to send broadcast messages. The default value is false.
308     * @type {?boolean}
309     * @syscap SystemCapability.Communication.NetStack
310     * @since 7
311     */
312    /**
313     * Whether to send broadcast messages. The default value is false.
314     * @type {?boolean}
315     * @syscap SystemCapability.Communication.NetStack
316     * @crossplatform
317     * @since 10
318     */
319    broadcast?: boolean;
320  }
321
322  /**
323   * Defines the status of the socket connection.
324   * @interface SocketStateBase
325   * @syscap SystemCapability.Communication.NetStack
326   * @since 7
327   */
328  /**
329   * Defines the status of the socket connection.
330   * @interface SocketStateBase
331   * @syscap SystemCapability.Communication.NetStack
332   * @crossplatform
333   * @since 10
334   */
335  export interface SocketStateBase {
336    /**
337     * Whether the connection is in the bound state.
338     * @type {boolean}
339     * @syscap SystemCapability.Communication.NetStack
340     * @since 7
341     */
342    /**
343     * Whether the connection is in the bound state.
344     * @type {boolean}
345     * @syscap SystemCapability.Communication.NetStack
346     * @crossplatform
347     * @since 10
348     */
349    isBound: boolean;
350
351    /**
352     * Whether the connection is in the closed state.
353     * @type {boolean}
354     * @syscap SystemCapability.Communication.NetStack
355     * @since 7
356     */
357    /**
358     * Whether the connection is in the closed state.
359     * @type {boolean}
360     * @syscap SystemCapability.Communication.NetStack
361     * @crossplatform
362     * @since 10
363     */
364    isClose: boolean;
365
366    /**
367     * Whether the connection is in the connected state.
368     * @type {boolean}
369     * @syscap SystemCapability.Communication.NetStack
370     * @since 7
371     */
372    /**
373     * Whether the connection is in the connected state.
374     * @type {boolean}
375     * @syscap SystemCapability.Communication.NetStack
376     * @crossplatform
377     * @since 10
378     */
379    isConnected: boolean;
380  }
381
382  /**
383   * Defines information about the socket connection.
384   * @interface SocketRemoteInfo
385   * @syscap SystemCapability.Communication.NetStack
386   * @since 7
387   */
388  /**
389   * Defines information about the socket connection.
390   * @interface SocketRemoteInfo
391   * @syscap SystemCapability.Communication.NetStack
392   * @crossplatform
393   * @since 10
394   */
395  export interface SocketRemoteInfo {
396    /**
397     * Bound IP address.
398     * @type {string}
399     * @syscap SystemCapability.Communication.NetStack
400     * @since 7
401     */
402    /**
403     * Bound IP address.
404     * @type {string}
405     * @syscap SystemCapability.Communication.NetStack
406     * @crossplatform
407     * @since 10
408     */
409    address: string;
410
411    /**
412     * Network protocol type. The options are as follows: IPv4, IPv6.
413     * @type {'IPv4' | 'IPv6'}
414     * @syscap SystemCapability.Communication.NetStack
415     * @since 7
416     */
417    /**
418     * Network protocol type. The options are as follows: IPv4, IPv6.
419     * @type {'IPv4' | 'IPv6'}
420     * @syscap SystemCapability.Communication.NetStack
421     * @crossplatform
422     * @since 10
423     */
424    family: 'IPv4' | 'IPv6';
425
426    /**
427     * Port number. The value ranges from 0 to 65535.
428     * @type {number}
429     * @syscap SystemCapability.Communication.NetStack
430     * @since 7
431     */
432    /**
433     * Port number. The value ranges from 0 to 65535.
434     * @type {number}
435     * @syscap SystemCapability.Communication.NetStack
436     * @crossplatform
437     * @since 10
438     */
439    port: number;
440
441    /**
442     * Length of the server response message, in bytes.
443     * @type {number}
444     * @syscap SystemCapability.Communication.NetStack
445     * @since 7
446     */
447    /**
448     * Length of the server response message, in bytes.
449     * @type {number}
450     * @syscap SystemCapability.Communication.NetStack
451     * @crossplatform
452     * @since 10
453     */
454    size: number;
455  }
456
457  /**
458   * Defines the local socket connection information.
459   * @interface LocalSocketMessageInfo
460   * @syscap SystemCapability.Communication.NetStack
461   * @since 11
462   */
463  /**
464   * Defines the local socket connection information.
465   * @interface LocalSocketMessageInfo
466   * @syscap SystemCapability.Communication.NetStack
467   * @crossplatform
468   * @since 12
469   */
470  export interface LocalSocketMessageInfo {
471    /**
472     * Message data.
473     * @type {ArrayBuffer}
474     * @syscap SystemCapability.Communication.NetStack
475     * @since 11
476     */
477    /**
478     * Message data.
479     * @type {ArrayBuffer}
480     * @syscap SystemCapability.Communication.NetStack
481     * @crossplatform
482     * @since 12
483     */
484    message: ArrayBuffer;
485
486    /**
487     * Bound local socket address.
488     * @type {string}
489     * @syscap SystemCapability.Communication.NetStack
490     * @since 11
491     */
492    /**
493     * Bound local socket address.
494     * @type {string}
495     * @syscap SystemCapability.Communication.NetStack
496     * @crossplatform
497     * @since 12
498     */
499    address: string;
500
501    /**
502     * Length of the message, in bytes.
503     * @type {number}
504     * @syscap SystemCapability.Communication.NetStack
505     * @since 11
506     */
507    /**
508     * Length of the message, in bytes.
509     * @type {number}
510     * @syscap SystemCapability.Communication.NetStack
511     * @crossplatform
512     * @since 12
513     */
514    size: number;
515  }
516
517  /**
518   * Defines a local address.
519   * @interface LocalAddress
520   * @syscap SystemCapability.Communication.NetStack
521   * @since 11
522   */
523  /**
524   * Defines a local address.
525   * @interface LocalAddress
526   * @syscap SystemCapability.Communication.NetStack
527   * @crossplatform
528   * @since 12
529   */
530  export interface LocalAddress {
531    /**
532     * LocalAddress address.
533     * @type {string}
534     * @syscap SystemCapability.Communication.NetStack
535     * @since 11
536     */
537    /**
538     * LocalAddress address.
539     * @type {string}
540     * @syscap SystemCapability.Communication.NetStack
541     * @crossplatform
542     * @since 12
543     */
544    address: string;
545  }
546
547  /**
548   * Defines LocalSocket connection parameters.
549   * @interface LocalConnectOptions
550   * @syscap SystemCapability.Communication.NetStack
551   * @since 11
552   */
553  /**
554   * Defines LocalSocket connection parameters.
555   * @interface LocalConnectOptions
556   * @syscap SystemCapability.Communication.NetStack
557   * @crossplatform
558   * @since 12
559   */
560  export interface LocalConnectOptions {
561    /**
562     * Bound Local address.
563     * @type {LocalAddress}
564     * @syscap SystemCapability.Communication.NetStack
565     * @since 11
566     */
567    /**
568     * Bound Local address.
569     * @type {LocalAddress}
570     * @syscap SystemCapability.Communication.NetStack
571     * @crossplatform
572     * @since 12
573     */
574    address: LocalAddress;
575
576    /**
577     * Timeout duration of the LocalSocket connection, in milliseconds.
578     * @type {?number}
579     * @syscap SystemCapability.Communication.NetStack
580     * @since 11
581     */
582    /**
583     * Timeout duration of the LocalSocket connection, in milliseconds.
584     * @type {?number}
585     * @syscap SystemCapability.Communication.NetStack
586     * @crossplatform
587     * @since 12
588     */
589    timeout?: number;
590  }
591
592  /**
593   * Defines the parameters for sending data over the LocalSocket connection.
594   * @interface LocalSendOptions
595   * @syscap SystemCapability.Communication.NetStack
596   * @since 11
597   */
598  /**
599   * Defines the parameters for sending data over the LocalSocket connection.
600   * @interface LocalSendOptions
601   * @syscap SystemCapability.Communication.NetStack
602   * @crossplatform
603   * @since 12
604   */
605  export interface LocalSendOptions {
606    /**
607     * Data to send.
608     * @type {string | ArrayBuffer}
609     * @syscap SystemCapability.Communication.NetStack
610     * @since 11
611     */
612    /**
613     * Data to send.
614     * @type {string | ArrayBuffer}
615     * @syscap SystemCapability.Communication.NetStack
616     * @crossplatform
617     * @since 12
618     */
619    data: string | ArrayBuffer;
620
621    /**
622     * Character encoding format.
623     * @type {?string}
624     * @syscap SystemCapability.Communication.NetStack
625     * @since 11
626     */
627    /**
628     * Character encoding format.
629     * @type {?string}
630     * @syscap SystemCapability.Communication.NetStack
631     * @crossplatform
632     * @since 12
633     */
634    encoding?: string;
635  }
636
637  /**
638   * Defines a UDPSocket connection.
639   * @interface UDPSocket
640   * @syscap SystemCapability.Communication.NetStack
641   * @since 7
642   */
643  /**
644   * Defines a UDPSocket connection.
645   * @interface UDPSocket
646   * @syscap SystemCapability.Communication.NetStack
647   * @crossplatform
648   * @since 10
649   */
650  export interface UDPSocket {
651    /**
652     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
653     * @permission ohos.permission.INTERNET
654     * @param { NetAddress } address - Destination address. {@link NetAddress}
655     * @param { AsyncCallback<void> } callback - the callback of bind.
656     * @throws { BusinessError } 401 - Parameter error.
657     * @throws { BusinessError } 201 - Permission denied.
658     * @syscap SystemCapability.Communication.NetStack
659     * @since 7
660     */
661    /**
662     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
663     * @permission ohos.permission.INTERNET
664     * @param { NetAddress } address - Destination address. {@link NetAddress}
665     * @param { AsyncCallback<void> } callback - the callback of bind.
666     * @throws { BusinessError } 401 - Parameter error.
667     * @throws { BusinessError } 201 - Permission denied.
668     * @syscap SystemCapability.Communication.NetStack
669     * @crossplatform
670     * @since 10
671     */
672    bind(address: NetAddress, callback: AsyncCallback<void>): void;
673
674    /**
675     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
676     * @permission ohos.permission.INTERNET
677     * @param { NetAddress } address - Destination address. {@link NetAddress}
678     * @returns { Promise<void> } The promise returned by the function.
679     * @throws { BusinessError } 401 - Parameter error.
680     * @throws { BusinessError } 201 - Permission denied.
681     * @syscap SystemCapability.Communication.NetStack
682     * @since 7
683     */
684    /**
685     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
686     * @permission ohos.permission.INTERNET
687     * @param { NetAddress } address - Destination address. {@link NetAddress}
688     * @returns { Promise<void> } The promise returned by the function.
689     * @throws { BusinessError } 401 - Parameter error.
690     * @throws { BusinessError } 201 - Permission denied.
691     * @syscap SystemCapability.Communication.NetStack
692     * @crossplatform
693     * @since 10
694     */
695    bind(address: NetAddress): Promise<void>;
696
697    /**
698     * Obtains the local address of a UDPSocket connection.
699     * @returns { Promise<NetAddress> } The promise returned by the function.
700     * @throws { BusinessError } 2300002 - System internal error.
701     * @throws { BusinessError } 2301009 - Bad file descriptor.
702     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
703     * @syscap SystemCapability.Communication.NetStack
704     * @since 12
705     */
706    getLocalAddress(): Promise<NetAddress>;
707
708    /**
709     * Sends data over a UDPSocket connection.
710     * @permission ohos.permission.INTERNET
711     * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
712     * @param { AsyncCallback<void> } callback - the callback of send.
713     * @throws { BusinessError } 401 - Parameter error.
714     * @throws { BusinessError } 201 - Permission denied.
715     * @syscap SystemCapability.Communication.NetStack
716     * @since 7
717     */
718    /**
719     * Sends data over a UDPSocket connection.
720     * @permission ohos.permission.INTERNET
721     * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
722     * @param { AsyncCallback<void> } callback - the callback of send.
723     * @throws { BusinessError } 401 - Parameter error.
724     * @throws { BusinessError } 201 - Permission denied.
725     * @syscap SystemCapability.Communication.NetStack
726     * @crossplatform
727     * @since 10
728     */
729    send(options: UDPSendOptions, callback: AsyncCallback<void>): void;
730
731    /**
732     * Sends data over a UDPSocket connection.
733     * @permission ohos.permission.INTERNET
734     * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
735     * @returns { Promise<void> } The promise returned by the function.
736     * @throws { BusinessError } 401 - Parameter error.
737     * @throws { BusinessError } 201 - Permission denied.
738     * @syscap SystemCapability.Communication.NetStack
739     * @since 7
740     */
741    /**
742     * Sends data over a UDPSocket connection.
743     * @permission ohos.permission.INTERNET
744     * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
745     * @returns { Promise<void> } The promise returned by the function.
746     * @throws { BusinessError } 401 - Parameter error.
747     * @throws { BusinessError } 201 - Permission denied.
748     * @syscap SystemCapability.Communication.NetStack
749     * @crossplatform
750     * @since 10
751     */
752    send(options: UDPSendOptions): Promise<void>;
753
754    /**
755     * Closes a UDPSocket connection.
756     * @permission ohos.permission.INTERNET
757     * @param { AsyncCallback<void> } callback - the callback of close.
758     * @throws { BusinessError } 201 - Permission denied.
759     * @syscap SystemCapability.Communication.NetStack
760     * @since 7
761     */
762    /**
763     * Closes a UDPSocket connection.
764     * @permission ohos.permission.INTERNET
765     * @param { AsyncCallback<void> } callback - the callback of close.
766     * @throws { BusinessError } 201 - Permission denied.
767     * @syscap SystemCapability.Communication.NetStack
768     * @crossplatform
769     * @since 10
770     */
771    close(callback: AsyncCallback<void>): void;
772
773    /**
774     * Closes a UDPSocket connection.
775     * @permission ohos.permission.INTERNET
776     * @returns { Promise<void> } The promise returned by the function.
777     * @throws { BusinessError } 201 - Permission denied.
778     * @syscap SystemCapability.Communication.NetStack
779     * @since 7
780     */
781    /**
782     * Closes a UDPSocket connection.
783     * @permission ohos.permission.INTERNET
784     * @returns { Promise<void> } The promise returned by the function.
785     * @throws { BusinessError } 201 - Permission denied.
786     * @syscap SystemCapability.Communication.NetStack
787     * @crossplatform
788     * @since 10
789     */
790    close(): Promise<void>;
791
792    /**
793     * Obtains the status of the UDPSocket connection.
794     * @permission ohos.permission.INTERNET
795     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}.
796     * @throws { BusinessError } 201 - Permission denied.
797     * @syscap SystemCapability.Communication.NetStack
798     * @since 7
799     */
800    /**
801     * Obtains the status of the UDPSocket connection.
802     * @permission ohos.permission.INTERNET
803     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}.
804     * @throws { BusinessError } 201 - Permission denied.
805     * @syscap SystemCapability.Communication.NetStack
806     * @crossplatform
807     * @since 10
808     */
809    getState(callback: AsyncCallback<SocketStateBase>): void;
810
811    /**
812     * Obtains the status of the UDPSocket connection.
813     * @permission ohos.permission.INTERNET
814     * @returns { Promise<SocketStateBase> } The promise returned by the function.
815     * @throws { BusinessError } 201 - Permission denied.
816     * @syscap SystemCapability.Communication.NetStack
817     * @since 7
818     */
819    /**
820     * Obtains the status of the UDPSocket connection.
821     * @permission ohos.permission.INTERNET
822     * @returns { Promise<SocketStateBase> } The promise returned by the function.
823     * @throws { BusinessError } 201 - Permission denied.
824     * @syscap SystemCapability.Communication.NetStack
825     * @crossplatform
826     * @since 10
827     */
828    getState(): Promise<SocketStateBase>;
829
830    /**
831     * Sets other attributes of the UDPSocket connection.
832     * @permission ohos.permission.INTERNET
833     * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
834     * @param { AsyncCallback<void> }callback - the callback of setExtraOptions.
835     * @throws { BusinessError } 401 - Parameter error.
836     * @throws { BusinessError } 201 - Permission denied.
837     * @syscap SystemCapability.Communication.NetStack
838     * @since 7
839     */
840    /**
841     * Sets other attributes of the UDPSocket connection.
842     * @permission ohos.permission.INTERNET
843     * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
844     * @param { AsyncCallback<void> }callback - the callback of setExtraOptions.
845     * @throws { BusinessError } 401 - Parameter error.
846     * @throws { BusinessError } 201 - Permission denied.
847     * @syscap SystemCapability.Communication.NetStack
848     * @crossplatform
849     * @since 10
850     */
851    setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback<void>): void;
852
853    /**
854     * Sets other attributes of the UDPSocket connection.
855     * @permission ohos.permission.INTERNET
856     * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
857     * @returns { Promise<void> } The promise returned by the function.
858     * @throws { BusinessError } 401 - Parameter error.
859     * @throws { BusinessError } 201 - Permission denied.
860     * @syscap SystemCapability.Communication.NetStack
861     * @since 7
862     */
863    /**
864     * Sets other attributes of the UDPSocket connection.
865     * @permission ohos.permission.INTERNET
866     * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
867     * @returns { Promise<void> } The promise returned by the function.
868     * @throws { BusinessError } 401 - Parameter error.
869     * @throws { BusinessError } 201 - Permission denied.
870     * @syscap SystemCapability.Communication.NetStack
871     * @crossplatform
872     * @since 10
873     */
874    setExtraOptions(options: UDPExtraOptions): Promise<void>;
875
876    /**
877     * Listens for message receiving events of the UDPSocket connection.
878     * @param { 'message' } type - Indicates Event name.
879     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
880     * @syscap SystemCapability.Communication.NetStack
881     * @since 7
882     */
883    /**
884     * Listens for message receiving events of the UDPSocket connection.
885     * @param { 'message' } type - Indicates Event name.
886     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
887     * @syscap SystemCapability.Communication.NetStack
888     * @crossplatform
889     * @since 10
890     */
891    /**
892     * Listens for message receiving events of the UDPSocket connection.
893     * @param { 'message' } type - Indicates Event name.
894     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
895     * @syscap SystemCapability.Communication.NetStack
896     * @crossplatform
897     * @since 11
898     */
899    on(type: 'message', callback: Callback<SocketMessageInfo>): void;
900
901    /**
902     * Cancels listening for message receiving events of the UDPSocket connection.
903     * @param { 'message' } type - Indicates Event name.
904     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
905     * @syscap SystemCapability.Communication.NetStack
906     * @since 7
907     */
908    /**
909     * Cancels listening for message receiving events of the UDPSocket connection.
910     * @param { 'message' } type - Indicates Event name.
911     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
912     * @syscap SystemCapability.Communication.NetStack
913     * @crossplatform
914     * @since 10
915     */
916    /**
917     * Cancels listening for message receiving events of the UDPSocket connection.
918     * @param { 'message' } type - Indicates Event name.
919     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
920     * @syscap SystemCapability.Communication.NetStack
921     * @crossplatform
922     * @since 11
923     */
924    off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
925
926    /**
927     * Listens for data packet message events or close events of the UDPSocket connection.
928     * @param { 'listening' | 'close' } type - Indicates Event name.
929     * @param { Callback<void> } callback - the callback used to return the result.
930     * @syscap SystemCapability.Communication.NetStack
931     * @since 7
932     */
933    /**
934     * Listens for data packet message events or close events of the UDPSocket connection.
935     * @param { 'listening' | 'close' } type - Indicates Event name.
936     * @param { Callback<void> } callback - the callback used to return the result.
937     * @syscap SystemCapability.Communication.NetStack
938     * @crossplatform
939     * @since 10
940     */
941    on(type: 'listening' | 'close', callback: Callback<void>): void;
942
943    /**
944     * Cancels listening for data packet message events or close events of the UDPSocket connection.
945     * @param { 'listening' | 'close' } type - Indicates Event name.
946     * @param { Callback<void> } callback - the callback used to return the result.
947     * @syscap SystemCapability.Communication.NetStack
948     * @since 7
949     */
950    /**
951     * Cancels listening for data packet message events or close events of the UDPSocket connection.
952     * @param { 'listening' | 'close' } type - Indicates Event name.
953     * @param { Callback<void> } callback - the callback used to return the result.
954     * @syscap SystemCapability.Communication.NetStack
955     * @crossplatform
956     * @since 10
957     */
958    off(type: 'listening' | 'close', callback?: Callback<void>): void;
959
960    /**
961     * Listens for error events of the UDPSocket connection.
962     * @param { 'error' } type - Indicates Event name.
963     * @param { ErrorCallback } callback - the callback used to return the result.
964     * @syscap SystemCapability.Communication.NetStack
965     * @since 7
966     */
967    /**
968     * Listens for error events of the UDPSocket connection.
969     * @param { 'error' } type - Indicates Event name.
970     * @param { ErrorCallback } callback - the callback used to return the result.
971     * @syscap SystemCapability.Communication.NetStack
972     * @crossplatform
973     * @since 10
974     */
975    on(type: 'error', callback: ErrorCallback): void;
976
977    /**
978     * Cancels listening for error events of the UDPSocket connection.
979     * @param { 'error' } type - Indicates Event name.
980     * @param { ErrorCallback } callback - the callback used to return the result.
981     * @syscap SystemCapability.Communication.NetStack
982     * @since 7
983     */
984    /**
985     * Cancels listening for error events of the UDPSocket connection.
986     * @param { 'error' } type - Indicates Event name.
987     * @param { ErrorCallback } callback - the callback used to return the result.
988     * @syscap SystemCapability.Communication.NetStack
989     * @crossplatform
990     * @since 10
991     */
992    off(type: 'error', callback?: ErrorCallback): void;
993  }
994
995  /**
996   * Defines a UDP MulticastSocket connection.
997   * @interface MulticastSocket
998   * @syscap SystemCapability.Communication.NetStack
999   * @since 11
1000   */
1001  /**
1002   * Defines a UDP MulticastSocket connection.
1003   * @extends UDPSocket
1004   * @interface MulticastSocket
1005   * @syscap SystemCapability.Communication.NetStack
1006   * @crossplatform
1007   * @since 12
1008   */
1009  export interface MulticastSocket extends UDPSocket {
1010    /**
1011     * Add the socket to the multicast group.
1012     * @permission ohos.permission.INTERNET
1013     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1014     * @param { AsyncCallback<void> } callback - The callback of addMembership.
1015     * @throws { BusinessError } 201 - Permission denied.
1016     * @throws { BusinessError } 401 - Parameter error.
1017     * @throws { BusinessError } 2301022 - Invalid argument.
1018     * @throws { BusinessError } 2301088 - Not a socket.
1019     * @throws { BusinessError } 2301098 - Address in use.
1020     * @syscap SystemCapability.Communication.NetStack
1021     * @since 11
1022     */
1023    /**
1024     * Add the socket to the multicast group.
1025     * @permission ohos.permission.INTERNET
1026     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1027     * @param { AsyncCallback<void> } callback - The callback of addMembership.
1028     * @throws { BusinessError } 201 - Permission denied.
1029     * @throws { BusinessError } 401 - Parameter error.
1030     * @throws { BusinessError } 2301022 - Invalid argument.
1031     * @throws { BusinessError } 2301088 - Not a socket.
1032     * @throws { BusinessError } 2301098 - Address in use.
1033     * @syscap SystemCapability.Communication.NetStack
1034     * @crossplatform
1035     * @since 12
1036     */
1037    addMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void;
1038
1039    /**
1040     * Add the socket to the multicast group.
1041     * @permission ohos.permission.INTERNET
1042     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1043     * @returns { Promise<void> } The promise returned by the function.
1044     * @throws { BusinessError } 201 - Permission denied.
1045     * @throws { BusinessError } 401 - Parameter error.
1046     * @throws { BusinessError } 2301088 - Not a socket.
1047     * @throws { BusinessError } 2301098 - Address in use.
1048     * @syscap SystemCapability.Communication.NetStack
1049     * @since 11
1050     */
1051    /**
1052     * Add the socket to the multicast group.
1053     * @permission ohos.permission.INTERNET
1054     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1055     * @returns { Promise<void> } The promise returned by the function.
1056     * @throws { BusinessError } 201 - Permission denied.
1057     * @throws { BusinessError } 401 - Parameter error.
1058     * @throws { BusinessError } 2301088 - Not a socket.
1059     * @throws { BusinessError } 2301098 - Address in use.
1060     * @syscap SystemCapability.Communication.NetStack
1061     * @crossplatform
1062     * @since 12
1063     */
1064    addMembership(multicastAddress: NetAddress): Promise<void>;
1065
1066    /**
1067     * Drop the socket from the multicast group.
1068     * @permission ohos.permission.INTERNET
1069     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1070     * @param { AsyncCallback<void> } callback - The callback of dropMembership.
1071     * @throws { BusinessError } 201 - Permission denied.
1072     * @throws { BusinessError } 401 - Parameter error.
1073     * @throws { BusinessError } 2301088 - Not a socket.
1074     * @throws { BusinessError } 2301098 - Address in use.
1075     * @syscap SystemCapability.Communication.NetStack
1076     * @since 11
1077     */
1078    /**
1079     * Drop the socket from the multicast group.
1080     * @permission ohos.permission.INTERNET
1081     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1082     * @param { AsyncCallback<void> } callback - The callback of dropMembership.
1083     * @throws { BusinessError } 201 - Permission denied.
1084     * @throws { BusinessError } 401 - Parameter error.
1085     * @throws { BusinessError } 2301088 - Not a socket.
1086     * @throws { BusinessError } 2301098 - Address in use.
1087     * @syscap SystemCapability.Communication.NetStack
1088     * @crossplatform
1089     * @since 12
1090     */
1091    dropMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void;
1092
1093    /**
1094     * Drop the socket from the multicast group.
1095     * @permission ohos.permission.INTERNET
1096     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1097     * @returns { Promise<void> } The promise returned by the function.
1098     * @throws { BusinessError } 201 - Permission denied.
1099     * @throws { BusinessError } 401 - Parameter error.
1100     * @throws { BusinessError } 2301088 - Not a socket.
1101     * @throws { BusinessError } 2301098 - Address in use.
1102     * @syscap SystemCapability.Communication.NetStack
1103     * @since 11
1104     */
1105    /**
1106     * Drop the socket from the multicast group.
1107     * @permission ohos.permission.INTERNET
1108     * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
1109     * @returns { Promise<void> } The promise returned by the function.
1110     * @throws { BusinessError } 201 - Permission denied.
1111     * @throws { BusinessError } 401 - Parameter error.
1112     * @throws { BusinessError } 2301088 - Not a socket.
1113     * @throws { BusinessError } 2301098 - Address in use.
1114     * @syscap SystemCapability.Communication.NetStack
1115     * @crossplatform
1116     * @since 12
1117     */
1118    dropMembership(multicastAddress: NetAddress): Promise<void>;
1119
1120    /**
1121     * Set the TTL value for socket multicast packets.
1122     * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
1123     * @param { AsyncCallback<void> } callback - The callback of setMulticastTTL.
1124     * @throws { BusinessError } 401 - Parameter error.
1125     * @throws { BusinessError } 2301022 - Invalid argument.
1126     * @throws { BusinessError } 2301088 - Not a socket.
1127     * @syscap SystemCapability.Communication.NetStack
1128     * @since 11
1129     */
1130    /**
1131     * Set the TTL value for socket multicast packets.
1132     * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
1133     * @param { AsyncCallback<void> } callback - The callback of setMulticastTTL.
1134     * @throws { BusinessError } 401 - Parameter error.
1135     * @throws { BusinessError } 2301022 - Invalid argument.
1136     * @throws { BusinessError } 2301088 - Not a socket.
1137     * @syscap SystemCapability.Communication.NetStack
1138     * @crossplatform
1139     * @since 12
1140     */
1141    setMulticastTTL(ttl: number, callback: AsyncCallback<void>): void;
1142
1143    /**
1144     * Set the TTL value for socket multicast packet.
1145     * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
1146     * @returns { Promise<void> } The promise returned by the function.
1147     * @throws { BusinessError } 401 - Parameter error.
1148     * @throws { BusinessError } 2301022 - Invalid argument.
1149     * @throws { BusinessError } 2301088 - Not a socket.
1150     * @syscap SystemCapability.Communication.NetStack
1151     * @since 11
1152     */
1153    /**
1154     * Set the TTL value for socket multicast packet.
1155     * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
1156     * @returns { Promise<void> } The promise returned by the function.
1157     * @throws { BusinessError } 401 - Parameter error.
1158     * @throws { BusinessError } 2301022 - Invalid argument.
1159     * @throws { BusinessError } 2301088 - Not a socket.
1160     * @syscap SystemCapability.Communication.NetStack
1161     * @crossplatform
1162     * @since 12
1163     */
1164    setMulticastTTL(ttl: number): Promise<void>;
1165
1166    /**
1167     * Get the TTL value of socket multicast packet.
1168     * @param { AsyncCallback<number> } callback - The callback of getMulticastTTL.
1169     * @throws { BusinessError } 401 - Parameter error.
1170     * @throws { BusinessError } 2301088 - Not a socket.
1171     * @syscap SystemCapability.Communication.NetStack
1172     * @since 11
1173     */
1174    /**
1175     * Get the TTL value of socket multicast packet.
1176     * @param { AsyncCallback<number> } callback - The callback of getMulticastTTL.
1177     * @throws { BusinessError } 401 - Parameter error.
1178     * @throws { BusinessError } 2301088 - Not a socket.
1179     * @syscap SystemCapability.Communication.NetStack
1180     * @crossplatform
1181     * @since 12
1182     */
1183    getMulticastTTL(callback: AsyncCallback<number>): void;
1184
1185    /**
1186     * Get the TTL value of socket multicast packet.
1187     * @returns { Promise<number> } The promise returned by the function.
1188     * @throws { BusinessError } 401 - Parameter error.
1189     * @throws { BusinessError } 2301088 - Not a socket.
1190     * @syscap SystemCapability.Communication.NetStack
1191     * @since 11
1192     */
1193    /**
1194     * Get the TTL value of socket multicast packet.
1195     * @returns { Promise<number> } The promise returned by the function.
1196     * @throws { BusinessError } 401 - Parameter error.
1197     * @throws { BusinessError } 2301088 - Not a socket.
1198     * @syscap SystemCapability.Communication.NetStack
1199     * @crossplatform
1200     * @since 12
1201     */
1202    getMulticastTTL(): Promise<number>;
1203
1204    /**
1205     * Set the loopback mode for the socket.
1206     * @param { boolean } flag - Whether to enable loopback mode.
1207     * @param { AsyncCallback<void> } callback - The callback of setLoopbackMode.
1208     * @throws { BusinessError } 401 - Parameter error.
1209     * @throws { BusinessError } 2301088 - Not a socket.
1210     * @syscap SystemCapability.Communication.NetStack
1211     * @since 11
1212     */
1213    /**
1214     * Set the loopback mode for the socket.
1215     * @param { boolean } flag - Whether to enable loopback mode.
1216     * @param { AsyncCallback<void> } callback - The callback of setLoopbackMode.
1217     * @throws { BusinessError } 401 - Parameter error.
1218     * @throws { BusinessError } 2301088 - Not a socket.
1219     * @syscap SystemCapability.Communication.NetStack
1220     * @crossplatform
1221     * @since 12
1222     */
1223    setLoopbackMode(flag: boolean, callback: AsyncCallback<void>): void;
1224
1225    /**
1226     * Set the loopback mode for the socket.
1227     * @param { boolean } flag - Whether to enable loopback mode.
1228     * @returns { Promise<void> } The promise returned by the function.
1229     * @throws { BusinessError } 401 - Parameter error.
1230     * @throws { BusinessError } 2301088 - Not a socket.
1231     * @syscap SystemCapability.Communication.NetStack
1232     * @since 11
1233     */
1234    /**
1235     * Set the loopback mode for the socket.
1236     * @param { boolean } flag - Whether to enable loopback mode.
1237     * @returns { Promise<void> } The promise returned by the function.
1238     * @throws { BusinessError } 401 - Parameter error.
1239     * @throws { BusinessError } 2301088 - Not a socket.
1240     * @syscap SystemCapability.Communication.NetStack
1241     * @crossplatform
1242     * @since 12
1243     */
1244    setLoopbackMode(flag: boolean): Promise<void>;
1245
1246    /**
1247     * Get the loopback mode of the socket.
1248     * @param { AsyncCallback<boolean> } callback - The callback of getLoopbackMode.
1249     * @throws { BusinessError } 401 - Parameter error.
1250     * @throws { BusinessError } 2301088 - Not a socket.
1251     * @syscap SystemCapability.Communication.NetStack
1252     * @since 11
1253     */
1254    /**
1255     * Get the loopback mode of the socket.
1256     * @param { AsyncCallback<boolean> } callback - The callback of getLoopbackMode.
1257     * @throws { BusinessError } 401 - Parameter error.
1258     * @throws { BusinessError } 2301088 - Not a socket.
1259     * @syscap SystemCapability.Communication.NetStack
1260     * @crossplatform
1261     * @since 12
1262     */
1263    getLoopbackMode(callback: AsyncCallback<boolean>): void;
1264
1265    /**
1266     * Get the loopback mode of the socket.
1267     * @returns { Promise<boolean> } The promise returned by the function.
1268     * @throws { BusinessError } 401 - Parameter error.
1269     * @throws { BusinessError } 2301088 - Not a socket.
1270     * @syscap SystemCapability.Communication.NetStack
1271     * @since 11
1272     */
1273    /**
1274     * Get the loopback mode of the socket.
1275     * @returns { Promise<boolean> } The promise returned by the function.
1276     * @throws { BusinessError } 401 - Parameter error.
1277     * @throws { BusinessError } 2301088 - Not a socket.
1278     * @syscap SystemCapability.Communication.NetStack
1279     * @crossplatform
1280     * @since 12
1281     */
1282    getLoopbackMode(): Promise<boolean>;
1283  }
1284
1285  /**
1286   * Defines a LocalSocket connection.
1287   * @interface LocalSocket
1288   * @syscap SystemCapability.Communication.NetStack
1289   * @since 11
1290   */
1291  /**
1292   * Defines a LocalSocket connection.
1293   * @interface LocalSocket
1294   * @syscap SystemCapability.Communication.NetStack
1295   * @crossplatform
1296   * @since 12
1297   */
1298  export interface LocalSocket {
1299    /**
1300     * Binds the Local address.
1301     * @param { LocalAddress } address - Destination address. {@link LocalAddress}
1302     * @returns { Promise<void> } The promise returned by the function.
1303     * @throws { BusinessError } 401 - Parameter error.
1304     * @throws { BusinessError } 2301013 - Insufficient permissions.
1305     * @throws { BusinessError } 2301022 - Invalid argument.
1306     * @throws { BusinessError } 2301098 - Address already in use.
1307     * @syscap SystemCapability.Communication.NetStack
1308     * @since 11
1309     */
1310    /**
1311     * Binds the Local address.
1312     * @param { LocalAddress } address - Destination address. {@link LocalAddress}
1313     * @returns { Promise<void> } The promise returned by the function.
1314     * @throws { BusinessError } 401 - Parameter error.
1315     * @throws { BusinessError } 2301013 - Insufficient permissions.
1316     * @throws { BusinessError } 2301022 - Invalid argument.
1317     * @throws { BusinessError } 2301098 - Address already in use.
1318     * @syscap SystemCapability.Communication.NetStack
1319     * @crossplatform
1320     * @since 12
1321     */
1322    bind(address: LocalAddress): Promise<void>;
1323
1324    /**
1325     * Sets up a connection to the specified Local address .
1326     * @param { LocalConnectOptions } options - Optional parameters {@link LocalConnectOptions}.
1327     * @returns { Promise<void> } The promise returned by the function.
1328     * @throws { BusinessError } 401 - Parameter error.
1329     * @throws { BusinessError } 2301013 - Insufficient permissions.
1330     * @throws { BusinessError } 2301022 - Invalid argument.
1331     * @throws { BusinessError } 2301111 - Connection refused.
1332     * @throws { BusinessError } 2301099 - Cannot assign requested address.
1333     * @syscap SystemCapability.Communication.NetStack
1334     * @since 11
1335     */
1336    /**
1337     * Sets up a connection to the specified Local address .
1338     * @param { LocalConnectOptions } options - Optional parameters {@link LocalConnectOptions}.
1339     * @returns { Promise<void> } The promise returned by the function.
1340     * @throws { BusinessError } 401 - Parameter error.
1341     * @throws { BusinessError } 2301013 - Insufficient permissions.
1342     * @throws { BusinessError } 2301022 - Invalid argument.
1343     * @throws { BusinessError } 2301111 - Connection refused.
1344     * @throws { BusinessError } 2301099 - Cannot assign requested address.
1345     * @syscap SystemCapability.Communication.NetStack
1346     * @crossplatform
1347     * @since 12
1348     */
1349    connect(options: LocalConnectOptions): Promise<void>;
1350
1351    /**
1352     * Sends data over a LocalSocket connection.
1353     * @param { LocalSendOptions } options - Optional parameters {@link LocalSendOptions}.
1354     * @returns { Promise<void> } The promise returned by the function.
1355     * @throws { BusinessError } 401 - Parameter error.
1356     * @throws { BusinessError } 2301011 - Operation would block.
1357     * @syscap SystemCapability.Communication.NetStack
1358     * @since 11
1359     */
1360    /**
1361     * Sends data over a LocalSocket connection.
1362     * @param { LocalSendOptions } options - Optional parameters {@link LocalSendOptions}.
1363     * @returns { Promise<void> } The promise returned by the function.
1364     * @throws { BusinessError } 401 - Parameter error.
1365     * @throws { BusinessError } 2301011 - Operation would block.
1366     * @syscap SystemCapability.Communication.NetStack
1367     * @crossplatform
1368     * @since 12
1369     */
1370    send(options: LocalSendOptions): Promise<void>;
1371
1372    /**
1373     * Closes a LocalSocket connection.
1374     * @returns { Promise<void> } The promise returned by the function.
1375     * @throws { BusinessError } 2301009 - Bad file descriptor.
1376     * @syscap SystemCapability.Communication.NetStack
1377     * @since 11
1378     */
1379    /**
1380     * Closes a LocalSocket connection.
1381     * @returns { Promise<void> } The promise returned by the function.
1382     * @throws { BusinessError } 2301009 - Bad file descriptor.
1383     * @syscap SystemCapability.Communication.NetStack
1384     * @crossplatform
1385     * @since 12
1386     */
1387    close(): Promise<void>;
1388
1389    /**
1390     * Obtains the status of the LocalSocket connection.
1391     * @returns { Promise<SocketStateBase> } The promise returned by the function.
1392     * @syscap SystemCapability.Communication.NetStack
1393     * @since 11
1394     */
1395    /**
1396     * Obtains the status of the LocalSocket connection.
1397     * @returns { Promise<SocketStateBase> } The promise returned by the function.
1398     * @syscap SystemCapability.Communication.NetStack
1399     * @crossplatform
1400     * @since 12
1401     */
1402    getState(): Promise<SocketStateBase>;
1403
1404    /**
1405     * Obtains the file descriptor of the LocalSocket connection.
1406     * @returns { Promise<number> } The promise returns the file descriptor of the LocalSocket connection.
1407     * @syscap SystemCapability.Communication.NetStack
1408     * @since 11
1409     */
1410    /**
1411     * Obtains the file descriptor of the LocalSocket connection.
1412     * @returns { Promise<number> } The promise returns the file descriptor of the LocalSocket connection.
1413     * @syscap SystemCapability.Communication.NetStack
1414     * @crossplatform
1415     * @since 12
1416     */
1417    getSocketFd(): Promise<number>;
1418
1419    /**
1420     * Sets other attributes of the LocalSocket connection.
1421     * @param { ExtraOptionsBase } options - Optional parameters {@link ExtraOptionsBase}.
1422     * @returns { Promise<void> } The promise returned by the function.
1423     * @throws { BusinessError } 401 - Parameter error.
1424     * @throws { BusinessError } 2301009 - Bad file descriptor.
1425     * @syscap SystemCapability.Communication.NetStack
1426     * @since 11
1427     */
1428    /**
1429     * Sets other attributes of the LocalSocket connection.
1430     * @param { ExtraOptionsBase } options - Optional parameters {@link ExtraOptionsBase}.
1431     * @returns { Promise<void> } The promise returned by the function.
1432     * @throws { BusinessError } 401 - Parameter error.
1433     * @throws { BusinessError } 2301009 - Bad file descriptor.
1434     * @syscap SystemCapability.Communication.NetStack
1435     * @crossplatform
1436     * @since 12
1437     */
1438    setExtraOptions(options: ExtraOptionsBase): Promise<void>;
1439
1440    /**
1441     * Gets other attributes of the LocalSocket connection.
1442     * @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
1443     * @throws { BusinessError } 2301009 - Bad file descriptor.
1444     * @syscap SystemCapability.Communication.NetStack
1445     * @since 11
1446     */
1447    /**
1448     * Gets other attributes of the LocalSocket connection.
1449     * @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
1450     * @throws { BusinessError } 2301009 - Bad file descriptor.
1451     * @syscap SystemCapability.Communication.NetStack
1452     * @crossplatform
1453     * @since 12
1454     */
1455    getExtraOptions(): Promise<ExtraOptionsBase>;
1456
1457    /**
1458     * Obtains the local address of a LocalSocket connection.
1459     * @returns { Promise<string> } The promise returned by the function.
1460     * @throws { BusinessError } 2300002 - System internal error.
1461     * @throws { BusinessError } 2301009 - Bad file descriptor.
1462     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
1463     * @syscap SystemCapability.Communication.NetStack
1464     * @since 12
1465     */
1466    getLocalAddress(): Promise<string>;
1467
1468    /**
1469     * Listens for message receiving events of the LocalSocket connection.
1470     * @param { 'message' } type Indicates Event name.
1471     * @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
1472     * @throws { BusinessError } 401 - Parameter error.
1473     * @syscap SystemCapability.Communication.NetStack
1474     * @since 11
1475     */
1476    /**
1477     * Listens for message receiving events of the LocalSocket connection.
1478     * @param { 'message' } type Indicates Event name.
1479     * @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
1480     * @throws { BusinessError } 401 - Parameter error.
1481     * @syscap SystemCapability.Communication.NetStack
1482     * @crossplatform
1483     * @since 12
1484     */
1485    on(type: 'message', callback: Callback<LocalSocketMessageInfo>): void;
1486
1487    /**
1488     * Cancels listening for message receiving events of the LocalSocket connection.
1489     * @param { 'message' } type Indicates Event name.
1490     * @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
1491     * @throws { BusinessError } 401 - Parameter error.
1492     * @syscap SystemCapability.Communication.NetStack
1493     * @since 11
1494     */
1495    /**
1496     * Cancels listening for message receiving events of the LocalSocket connection.
1497     * @param { 'message' } type Indicates Event name.
1498     * @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
1499     * @throws { BusinessError } 401 - Parameter error.
1500     * @syscap SystemCapability.Communication.NetStack
1501     * @crossplatform
1502     * @since 12
1503     */
1504    off(type: 'message', callback?: Callback<LocalSocketMessageInfo>): void;
1505
1506    /**
1507     * Listens for connection events of the LocalSocket connection.
1508     * @param { 'connect' } type - Indicates Event name.
1509     * @param { Callback<void> } callback - the callback used to return the result.
1510     * @throws { BusinessError } 401 - Parameter error.
1511     * @syscap SystemCapability.Communication.NetStack
1512     * @since 11
1513     */
1514    /**
1515     * Listens for connection events of the LocalSocket connection.
1516     * @param { 'connect' } type - Indicates Event name.
1517     * @param { Callback<void> } callback - the callback used to return the result.
1518     * @throws { BusinessError } 401 - Parameter error.
1519     * @syscap SystemCapability.Communication.NetStack
1520     * @crossplatform
1521     * @since 12
1522     */
1523    on(type: 'connect', callback: Callback<void>): void;
1524
1525    /**
1526     * Cancels listening for connection events of the LocalSocket connection.
1527     * @param { 'connect' } type - Indicates Event name.
1528     * @param { Callback<void> } callback - the callback used to return the result.
1529     * @throws { BusinessError } 401 - Parameter error.
1530     * @syscap SystemCapability.Communication.NetStack
1531     * @since 11
1532     */
1533    /**
1534     * Cancels listening for connection events of the LocalSocket connection.
1535     * @param { 'connect' } type - Indicates Event name.
1536     * @param { Callback<void> } callback - the callback used to return the result.
1537     * @throws { BusinessError } 401 - Parameter error.
1538     * @syscap SystemCapability.Communication.NetStack
1539     * @crossplatform
1540     * @since 12
1541     */
1542    off(type: 'connect', callback?: Callback<void>): void;
1543
1544    /**
1545     * Listens for close events of the LocalSocket connection.
1546     * @param { 'close' } type - Indicates Event name.
1547     * @param { Callback<void> } callback - the callback used to return the result.
1548     * @throws { BusinessError } 401 - Parameter error.
1549     * @syscap SystemCapability.Communication.NetStack
1550     * @since 11
1551     */
1552    /**
1553     * Listens for close events of the LocalSocket connection.
1554     * @param { 'close' } type - Indicates Event name.
1555     * @param { Callback<void> } callback - the callback used to return the result.
1556     * @throws { BusinessError } 401 - Parameter error.
1557     * @syscap SystemCapability.Communication.NetStack
1558     * @crossplatform
1559     * @since 12
1560     */
1561    on(type: 'close', callback: Callback<void>): void;
1562
1563    /**
1564     * Cancels listening for close events of the LocalSocket connection.
1565     * @param { 'close' } type - Indicates Event name.
1566     * @param { Callback<void> } callback - the callback used to return the result.
1567     * @throws { BusinessError } 401 - Parameter error.
1568     * @syscap SystemCapability.Communication.NetStack
1569     * @since 11
1570     */
1571    /**
1572     * Cancels listening for close events of the LocalSocket connection.
1573     * @param { 'close' } type - Indicates Event name.
1574     * @param { Callback<void> } callback - the callback used to return the result.
1575     * @throws { BusinessError } 401 - Parameter error.
1576     * @syscap SystemCapability.Communication.NetStack
1577     * @crossplatform
1578     * @since 12
1579     */
1580    off(type: 'close', callback?: Callback<void>): void;
1581
1582    /**
1583     * Listens for error events of the LocalSocket connection.
1584     * @param { 'error' } type - Indicates Event name.
1585     * @param { ErrorCallback } callback - the callback used to return the result.
1586     * @throws { BusinessError } 401 - Parameter error.
1587     * @syscap SystemCapability.Communication.NetStack
1588     * @since 11
1589     */
1590    /**
1591     * Listens for error events of the LocalSocket connection.
1592     * @param { 'error' } type - Indicates Event name.
1593     * @param { ErrorCallback } callback - the callback used to return the result.
1594     * @throws { BusinessError } 401 - Parameter error.
1595     * @syscap SystemCapability.Communication.NetStack
1596     * @crossplatform
1597     * @since 12
1598     */
1599    on(type: 'error', callback: ErrorCallback): void;
1600
1601    /**
1602     * Cancels listening for error events of the LocalSocket connection.
1603     * @param { 'error' } type - Indicates Event name.
1604     * @param { ErrorCallback } callback - the callback used to return the result.
1605     * @throws { BusinessError } 401 - Parameter error.
1606     * @syscap SystemCapability.Communication.NetStack
1607     * @since 11
1608     */
1609    /**
1610     * Cancels listening for error events of the LocalSocket connection.
1611     * @param { 'error' } type - Indicates Event name.
1612     * @param { ErrorCallback } callback - the callback used to return the result.
1613     * @throws { BusinessError } 401 - Parameter error.
1614     * @syscap SystemCapability.Communication.NetStack
1615     * @crossplatform
1616     * @since 12
1617     */
1618    off(type: 'error', callback?: ErrorCallback): void;
1619  }
1620
1621  /**
1622   * Defines the connection of the LocalSocket client and server.
1623   * @interface LocalSocketConnection
1624   * @syscap SystemCapability.Communication.NetStack
1625   * @since 11
1626   */
1627  /**
1628   * Defines the connection of the LocalSocket client and server.
1629   * @interface LocalSocketConnection
1630   * @syscap SystemCapability.Communication.NetStack
1631   * @crossplatform
1632   * @since 12
1633   */
1634  export interface LocalSocketConnection {
1635    /**
1636     * The id of a client connects to the LocalSocketServer.
1637     * @type {number}
1638     * @syscap SystemCapability.Communication.NetStack
1639     * @since 11
1640     */
1641    /**
1642     * The id of a client connects to the LocalSocketServer.
1643     * @type {number}
1644     * @syscap SystemCapability.Communication.NetStack
1645     * @crossplatform
1646     * @since 12
1647     */
1648    clientId: number;
1649
1650    /**
1651     * Sends data over a LocalSocketServer connection to client.
1652     * @param { LocalSendOptions } options - Parameters for sending data {@link LocalSendOptions}.
1653     * @returns { Promise<void> } The promise returned by the function.
1654     * @throws { BusinessError } 401 - Parameter error.
1655     * @throws { BusinessError } 2301011 - Operation would block.
1656     * @syscap SystemCapability.Communication.NetStack
1657     * @since 11
1658     */
1659    /**
1660     * Sends data over a LocalSocketServer connection to client.
1661     * @param { LocalSendOptions } options - Parameters for sending data {@link LocalSendOptions}.
1662     * @returns { Promise<void> } The promise returned by the function.
1663     * @throws { BusinessError } 401 - Parameter error.
1664     * @throws { BusinessError } 2301011 - Operation would block.
1665     * @syscap SystemCapability.Communication.NetStack
1666     * @crossplatform
1667     * @since 12
1668     */
1669    send(options: LocalSendOptions): Promise<void>;
1670
1671    /**
1672     * Closes a LocalSocket client connection.
1673     * @returns { Promise<void> } The promise returned by the function.
1674     * @throws { BusinessError } 2301009 - Bad file descriptor.
1675     * @syscap SystemCapability.Communication.NetStack
1676     * @since 11
1677     */
1678    /**
1679     * Closes a LocalSocket client connection.
1680     * @returns { Promise<void> } The promise returned by the function.
1681     * @throws { BusinessError } 2301009 - Bad file descriptor.
1682     * @syscap SystemCapability.Communication.NetStack
1683     * @crossplatform
1684     * @since 12
1685     */
1686    close(): Promise<void>;
1687
1688    /**
1689     * Obtains the local address of a LocalSocket client connection.
1690     * @returns { Promise<string> } The promise returned by the function.
1691     * @throws { BusinessError } 2300002 - System internal error.
1692     * @throws { BusinessError } 2301009 - Bad file descriptor.
1693     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
1694     * @syscap SystemCapability.Communication.NetStack
1695     * @since 12
1696     */
1697    getLocalAddress(): Promise<string>;
1698
1699    /**
1700     * Listens for message receiving events of the LocalSocketConnection.
1701     * @param { 'message' } type - Indicates Event name.
1702     * @param { Callback<LocalSocketMessageInfo> } callback - The callback of on.
1703     * @throws { BusinessError } 401 - Parameter error.
1704     * @syscap SystemCapability.Communication.NetStack
1705     * @since 11
1706     */
1707    /**
1708     * Listens for message receiving events of the LocalSocketConnection.
1709     * @param { 'message' } type - Indicates Event name.
1710     * @param { Callback<LocalSocketMessageInfo> } callback - The callback of on.
1711     * @throws { BusinessError } 401 - Parameter error.
1712     * @syscap SystemCapability.Communication.NetStack
1713     * @crossplatform
1714     * @since 12
1715     */
1716    on(type: 'message', callback: Callback<LocalSocketMessageInfo>): void;
1717
1718    /**
1719     * Cancels listening for message receiving events of the LocalSocketConnection.
1720     * @param { 'message' } type - Indicates Event name.
1721     * @param { Callback<LocalSocketMessageInfo> } callback - The callback of off.
1722     * @throws { BusinessError } 401 - Parameter error.
1723     * @syscap SystemCapability.Communication.NetStack
1724     * @since 11
1725     */
1726    /**
1727     * Cancels listening for message receiving events of the LocalSocketConnection.
1728     * @param { 'message' } type - Indicates Event name.
1729     * @param { Callback<LocalSocketMessageInfo> } callback - The callback of off.
1730     * @throws { BusinessError } 401 - Parameter error.
1731     * @syscap SystemCapability.Communication.NetStack
1732     * @crossplatform
1733     * @since 12
1734     */
1735    off(type: 'message', callback?: Callback<LocalSocketMessageInfo>): void;
1736
1737    /**
1738     * Listens for close events of the LocalSocketConnection.
1739     * @param { 'close' } type - Indicates Event name.
1740     * @param { Callback<void> } callback - The callback of on.
1741     * @throws { BusinessError } 401 - Parameter error.
1742     * @syscap SystemCapability.Communication.NetStack
1743     * @since 11
1744     */
1745    /**
1746     * Listens for close events of the LocalSocketConnection.
1747     * @param { 'close' } type - Indicates Event name.
1748     * @param { Callback<void> } callback - The callback of on.
1749     * @throws { BusinessError } 401 - Parameter error.
1750     * @syscap SystemCapability.Communication.NetStack
1751     * @crossplatform
1752     * @since 12
1753     */
1754    on(type: 'close', callback: Callback<void>): void;
1755
1756    /**
1757     * Cancels listening for close events of the LocalSocketConnection.
1758     * @param { 'close' } type - Indicates Event name.
1759     * @param { Callback<void> } callback - The callback of off.
1760     * @throws { BusinessError } 401 - Parameter error.
1761     * @syscap SystemCapability.Communication.NetStack
1762     * @since 11
1763     */
1764    /**
1765     * Cancels listening for close events of the LocalSocketConnection.
1766     * @param { 'close' } type - Indicates Event name.
1767     * @param { Callback<void> } callback - The callback of off.
1768     * @throws { BusinessError } 401 - Parameter error.
1769     * @syscap SystemCapability.Communication.NetStack
1770     * @crossplatform
1771     * @since 12
1772     */
1773    off(type: 'close', callback?: Callback<void>): void;
1774
1775    /**
1776     * Listens for error events of the LocalSocketConnection.
1777     * @param { 'error' } type - Indicates Event name.
1778     * @param { ErrorCallback } callback - The callback of on.
1779     * @throws { BusinessError } 401 - Parameter error.
1780     * @syscap SystemCapability.Communication.NetStack
1781     * @since 11
1782     */
1783    /**
1784     * Listens for error events of the LocalSocketConnection.
1785     * @param { 'error' } type - Indicates Event name.
1786     * @param { ErrorCallback } callback - The callback of on.
1787     * @throws { BusinessError } 401 - Parameter error.
1788     * @syscap SystemCapability.Communication.NetStack
1789     * @crossplatform
1790     * @since 12
1791     */
1792    on(type: 'error', callback: ErrorCallback): void;
1793
1794    /**
1795     * Cancels listening for error events of the LocalSocketConnection.
1796     * @param { 'error' } type - Indicates Event name.
1797     * @param { ErrorCallback } callback - The callback of off.
1798     * @throws { BusinessError } 401 - Parameter error.
1799     * @syscap SystemCapability.Communication.NetStack
1800     * @since 11
1801     */
1802    /**
1803     * Cancels listening for error events of the LocalSocketConnection.
1804     * @param { 'error' } type - Indicates Event name.
1805     * @param { ErrorCallback } callback - The callback of off.
1806     * @throws { BusinessError } 401 - Parameter error.
1807     * @syscap SystemCapability.Communication.NetStack
1808     * @crossplatform
1809     * @since 12
1810     */
1811    off(type: 'error', callback?: ErrorCallback): void;
1812  }
1813
1814  /**
1815   * Defines a LocalSocket server connection.
1816   * @interface LocalSocketServer
1817   * @syscap SystemCapability.Communication.NetStack
1818   * @since 11
1819   */
1820  /**
1821   * Defines a LocalSocket server connection.
1822   * @interface LocalSocketServer
1823   * @syscap SystemCapability.Communication.NetStack
1824   * @crossplatform
1825   * @since 12
1826   */
1827  export interface LocalSocketServer {
1828    /**
1829     * Binds the Local address.
1830     * <p>Listens for a LocalSocket connection to be made to this socket and accepts it. This interface uses multiple threads
1831     * for accept processing and uses poll multiplex to process client connections.</p>
1832     * @param { LocalAddress } address - Network address information {@link LocalAddress}.
1833     * @returns { Promise<void> } The promise returned by the function.
1834     * @throws { BusinessError } 401 - Parameter error.
1835     * @throws { BusinessError } 2303109 - Bad file number.
1836     * @throws { BusinessError } 2301013 - Insufficient permissions.
1837     * @throws { BusinessError } 2301022 - Invalid argument.
1838     * @throws { BusinessError } 2301098 - Address already in use.
1839     * @syscap SystemCapability.Communication.NetStack
1840     * @since 11
1841     */
1842    /**
1843     * Binds the Local address.
1844     * <p>Listens for a LocalSocket connection to be made to this socket and accepts it. This interface uses multiple threads
1845     * for accept processing and uses poll multiplex to process client connections.</p>
1846     * @param { LocalAddress } address - Network address information {@link LocalAddress}.
1847     * @returns { Promise<void> } The promise returned by the function.
1848     * @throws { BusinessError } 401 - Parameter error.
1849     * @throws { BusinessError } 2303109 - Bad file number.
1850     * @throws { BusinessError } 2301013 - Insufficient permissions.
1851     * @throws { BusinessError } 2301022 - Invalid argument.
1852     * @throws { BusinessError } 2301098 - Address already in use.
1853     * @syscap SystemCapability.Communication.NetStack
1854     * @crossplatform
1855     * @since 12
1856     */
1857    listen(address: LocalAddress): Promise<void>;
1858
1859    /**
1860     * Obtains the status of the LocalSocketServer connection.
1861     * @returns { Promise<SocketStateBase> } The promise returned by the function.
1862     * @syscap SystemCapability.Communication.NetStack
1863     * @since 11
1864     */
1865    /**
1866     * Obtains the status of the LocalSocketServer connection.
1867     * @returns { Promise<SocketStateBase> } The promise returned by the function.
1868     * @syscap SystemCapability.Communication.NetStack
1869     * @crossplatform
1870     * @since 12
1871     */
1872    getState(): Promise<SocketStateBase>;
1873
1874    /**
1875     * Sets other attributes of the LocalSocketServer connection.
1876     * @param { ExtraOptionsBase } options - Parameters of the attributes {@link ExtraOptionsBase}.
1877     * @returns { Promise<void> } The promise returned by the function.
1878     * @throws { BusinessError } 401 - Parameter error.
1879     * @throws { BusinessError } 2301009 - Bad file descriptor.
1880     * @syscap SystemCapability.Communication.NetStack
1881     * @since 11
1882     */
1883    /**
1884     * Sets other attributes of the LocalSocketServer connection.
1885     * @param { ExtraOptionsBase } options - Parameters of the attributes {@link ExtraOptionsBase}.
1886     * @returns { Promise<void> } The promise returned by the function.
1887     * @throws { BusinessError } 401 - Parameter error.
1888     * @throws { BusinessError } 2301009 - Bad file descriptor.
1889     * @syscap SystemCapability.Communication.NetStack
1890     * @crossplatform
1891     * @since 12
1892     */
1893    setExtraOptions(options: ExtraOptionsBase): Promise<void>;
1894
1895    /**
1896     * Gets other attributes of the LocalSocket connection.
1897     * @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
1898     * @throws { BusinessError } 401 - Parameter error.
1899     * @syscap SystemCapability.Communication.NetStack
1900     * @since 11
1901     */
1902    /**
1903     * Gets other attributes of the LocalSocket connection.
1904     * @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
1905     * @throws { BusinessError } 401 - Parameter error.
1906     * @syscap SystemCapability.Communication.NetStack
1907     * @crossplatform
1908     * @since 12
1909     */
1910    getExtraOptions(): Promise<ExtraOptionsBase>;
1911
1912    /**
1913     * Obtains the local address of the LocalSocketServer connection.
1914     * @returns { Promise<string> } The promise returned by the function.
1915     * @throws { BusinessError } 2300002 - System internal error.
1916     * @throws { BusinessError } 2301009 - Bad file descriptor.
1917     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
1918     * @syscap SystemCapability.Communication.NetStack
1919     * @since 12
1920     */
1921    getLocalAddress(): Promise<string>;
1922
1923    /**
1924     * Listens for connect events of the LocalSocketServer connection.
1925     * @param { 'connect' } type - Indicates Event name.
1926     * @param { Callback<LocalSocketConnection> } callback - The callback of on.
1927     * @throws { BusinessError } 401 - Parameter error.
1928     * @syscap SystemCapability.Communication.NetStack
1929     * @since 11
1930     */
1931    /**
1932     * Listens for connect events of the LocalSocketServer connection.
1933     * @param { 'connect' } type - Indicates Event name.
1934     * @param { Callback<LocalSocketConnection> } callback - The callback of on.
1935     * @throws { BusinessError } 401 - Parameter error.
1936     * @syscap SystemCapability.Communication.NetStack
1937     * @crossplatform
1938     * @since 12
1939     */
1940    on(type: 'connect', callback: Callback<LocalSocketConnection>): void;
1941
1942    /**
1943     * Cancels listening for connect events of the LocalSocketServer connection.
1944     * @param { 'connect' } type - Indicates Event name.
1945     * @param { Callback<LocalSocketConnection> } callback - The callback of off.
1946     * @throws { BusinessError } 401 - Parameter error.
1947     * @syscap SystemCapability.Communication.NetStack
1948     * @since 11
1949     */
1950    /**
1951     * Cancels listening for connect events of the LocalSocketServer connection.
1952     * @param { 'connect' } type - Indicates Event name.
1953     * @param { Callback<LocalSocketConnection> } callback - The callback of off.
1954     * @throws { BusinessError } 401 - Parameter error.
1955     * @syscap SystemCapability.Communication.NetStack
1956     * @crossplatform
1957     * @since 12
1958     */
1959    off(type: 'connect', callback?: Callback<LocalSocketConnection>): void;
1960
1961    /**
1962     * Listens for error events of the LocalSocketServer connection.
1963     * @param { 'error' } type - Indicates Event name.
1964     * @param { ErrorCallback } callback - The callback of on.
1965     * @throws { BusinessError } 401 - Parameter error.
1966     * @syscap SystemCapability.Communication.NetStack
1967     * @since 11
1968     */
1969    /**
1970     * Listens for error events of the LocalSocketServer connection.
1971     * @param { 'error' } type - Indicates Event name.
1972     * @param { ErrorCallback } callback - The callback of on.
1973     * @throws { BusinessError } 401 - Parameter error.
1974     * @syscap SystemCapability.Communication.NetStack
1975     * @crossplatform
1976     * @since 12
1977     */
1978    on(type: 'error', callback: ErrorCallback): void;
1979
1980    /**
1981     * Cancels listening for error events of the LocalSocketServer connection.
1982     * @param { 'error' } type - Indicates Event name.
1983     * @param { ErrorCallback } callback - The callback of off.
1984     * @throws { BusinessError } 401 - Parameter error.
1985     * @syscap SystemCapability.Communication.NetStack
1986     * @since 11
1987     */
1988    /**
1989     * Cancels listening for error events of the LocalSocketServer connection.
1990     * @param { 'error' } type - Indicates Event name.
1991     * @param { ErrorCallback } callback - The callback of off.
1992     * @throws { BusinessError } 401 - Parameter error.
1993     * @syscap SystemCapability.Communication.NetStack
1994     * @crossplatform
1995     * @since 12
1996     */
1997    off(type: 'error', callback?: ErrorCallback): void;
1998  }
1999
2000  /**
2001   * Defines TCPSocket connection parameters.
2002   * @interface TCPConnectOptions
2003   * @syscap SystemCapability.Communication.NetStack
2004   * @since 7
2005   */
2006  /**
2007   * Defines TCPSocket connection parameters.
2008   * @interface TCPConnectOptions
2009   * @syscap SystemCapability.Communication.NetStack
2010   * @crossplatform
2011   * @since 10
2012   */
2013  export interface TCPConnectOptions {
2014    /**
2015     * Bound IP address and port number.
2016     * @type { NetAddress }
2017     * @syscap SystemCapability.Communication.NetStack
2018     * @since 7
2019     */
2020    /**
2021     * Bound IP address and port number.
2022     * @type { NetAddress }
2023     * @syscap SystemCapability.Communication.NetStack
2024     * @crossplatform
2025     * @since 10
2026     */
2027    address: NetAddress;
2028
2029    /**
2030     * Timeout duration of the TCPSocket connection, in milliseconds.
2031     * @type { ?number }
2032     * @syscap SystemCapability.Communication.NetStack
2033     * @since 7
2034     */
2035    /**
2036     * Timeout duration of the TCPSocket connection, in milliseconds.
2037     * @type { ?number }
2038     * @syscap SystemCapability.Communication.NetStack
2039     * @crossplatform
2040     * @since 10
2041     */
2042    timeout?: number;
2043  }
2044
2045  /**
2046   * Defines the parameters for sending data over the TCPSocket connection.
2047   * @interface TCPSendOptions
2048   * @syscap SystemCapability.Communication.NetStack
2049   * @since 7
2050   */
2051  /**
2052   * Defines the parameters for sending data over the TCPSocket connection.
2053   * @interface TCPSendOptions
2054   * @syscap SystemCapability.Communication.NetStack
2055   * @crossplatform
2056   * @since 10
2057   */
2058  export interface TCPSendOptions {
2059    /**
2060     * Data to send.
2061     * @type { string | ArrayBuffer }
2062     * @syscap SystemCapability.Communication.NetStack
2063     * @since 7
2064     */
2065    /**
2066     * Data to send.
2067     * @type { string | ArrayBuffer }
2068     * @syscap SystemCapability.Communication.NetStack
2069     * @crossplatform
2070     * @since 10
2071     */
2072    data: string | ArrayBuffer;
2073
2074    /**
2075     * Character encoding format.
2076     * @type { ?string }
2077     * @syscap SystemCapability.Communication.NetStack
2078     * @since 7
2079     */
2080    /**
2081     * Character encoding format.
2082     * @type { ?string }
2083     * @syscap SystemCapability.Communication.NetStack
2084     * @crossplatform
2085     * @since 10
2086     */
2087    encoding?: string;
2088  }
2089
2090  /**
2091   * Defines other properties of the TCPSocket connection.
2092   * @interface TCPExtraOptions
2093   * @syscap SystemCapability.Communication.NetStack
2094   * @since 7
2095   */
2096  /**
2097   * Defines other properties of the TCPSocket connection.
2098   * @extends ExtraOptionsBase
2099   * @interface TCPExtraOptions
2100   * @syscap SystemCapability.Communication.NetStack
2101   * @crossplatform
2102   * @since 10
2103   */
2104  export interface TCPExtraOptions extends ExtraOptionsBase {
2105    /**
2106     * Whether to keep the connection alive. The default value is false.
2107     * @type { ?boolean }
2108     * @syscap SystemCapability.Communication.NetStack
2109     * @since 7
2110     */
2111    /**
2112     * Whether to keep the connection alive. The default value is false.
2113     * @type { ?boolean }
2114     * @syscap SystemCapability.Communication.NetStack
2115     * @crossplatform
2116     * @since 10
2117     */
2118    keepAlive?: boolean;
2119
2120    /**
2121     * Whether to enable OOBInline. The default value is false.
2122     * @type { ?boolean }
2123     * @syscap SystemCapability.Communication.NetStack
2124     * @since 7
2125     */
2126    /**
2127     * Whether to enable OOBInline. The default value is false.
2128     * @type { ?boolean }
2129     * @syscap SystemCapability.Communication.NetStack
2130     * @crossplatform
2131     * @since 10
2132     */
2133    OOBInline?: boolean;
2134
2135    /**
2136     * Whether to enable no-delay on the TCPSocket connection. The default value is false.
2137     * @type { ?boolean }
2138     * @syscap SystemCapability.Communication.NetStack
2139     * @since 7
2140     */
2141    /**
2142     * Whether to enable no-delay on the TCPSocket connection. The default value is false.
2143     * @type { ?boolean }
2144     * @syscap SystemCapability.Communication.NetStack
2145     * @crossplatform
2146     * @since 10
2147     */
2148    TCPNoDelay?: boolean;
2149
2150    /**
2151     * Socket linger.
2152     * @type { ?object }
2153     * @syscap SystemCapability.Communication.NetStack
2154     * @crossplatform
2155     * @since 7
2156     */
2157    /**
2158     * Socket linger.
2159     * @type { ?object }
2160     * @syscap SystemCapability.Communication.NetStack
2161     * @crossplatform
2162     * @since 10
2163     */
2164    socketLinger?: { on: boolean, linger: number };
2165  }
2166
2167  /**
2168   * Defines a TCPSocket connection.
2169   * @interface TCPSocket
2170   * @syscap SystemCapability.Communication.NetStack
2171   * @since 7
2172   */
2173  /**
2174   * Defines a TCPSocket connection.
2175   * @interface TCPSocket
2176   * @syscap SystemCapability.Communication.NetStack
2177   * @crossplatform
2178   * @since 10
2179   */
2180  export interface TCPSocket {
2181    /**
2182     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2183     * @permission ohos.permission.INTERNET
2184     * @param { NetAddress } address - Destination address. {@link NetAddress}
2185     * @param { AsyncCallback<void> } callback - Return the callback of bind.
2186     * @throws { BusinessError } 401 - Parameter error.
2187     * @throws { BusinessError } 201 - Permission denied.
2188     * @syscap SystemCapability.Communication.NetStack
2189     * @since 7
2190     */
2191    /**
2192     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2193     * @permission ohos.permission.INTERNET
2194     * @param { NetAddress } address - Destination address. {@link NetAddress}
2195     * @param { AsyncCallback<void> } callback - the callback of bind.
2196     * @throws { BusinessError } 401 - Parameter error.
2197     * @throws { BusinessError } 201 - Permission denied.
2198     * @syscap SystemCapability.Communication.NetStack
2199     * @crossplatform
2200     * @since 10
2201     */
2202    bind(address: NetAddress, callback: AsyncCallback<void>): void;
2203
2204    /**
2205     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2206     * @permission ohos.permission.INTERNET
2207     * @param { NetAddress } address - Destination address. {@link NetAddress}
2208     * @returns { Promise<void> } The promise returned by the function.
2209     * @throws { BusinessError } 401 - Parameter error.
2210     * @throws { BusinessError } 201 - Permission denied.
2211     * @syscap SystemCapability.Communication.NetStack
2212     * @since 7
2213     */
2214    /**
2215     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2216     * @permission ohos.permission.INTERNET
2217     * @param { NetAddress } address - Destination address. {@link NetAddress}
2218     * @returns { Promise<void> } The promise returned by the function.
2219     * @throws { BusinessError } 401 - Parameter error.
2220     * @throws { BusinessError } 201 - Permission denied.
2221     * @syscap SystemCapability.Communication.NetStack
2222     * @crossplatform
2223     * @since 10
2224     */
2225    bind(address: NetAddress): Promise<void>;
2226
2227    /**
2228     * Sets up a connection to the specified IP address and port number.
2229     * @permission ohos.permission.INTERNET
2230     * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
2231     * @param { AsyncCallback<void> } callback - the callback of connect.
2232     * @throws { BusinessError } 401 - Parameter error.
2233     * @throws { BusinessError } 201 - Permission denied.
2234     * @syscap SystemCapability.Communication.NetStack
2235     * @since 7
2236     */
2237    /**
2238     * Sets up a connection to the specified IP address and port number.
2239     * @permission ohos.permission.INTERNET
2240     * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
2241     * @param { AsyncCallback<void> } callback - the callback of connect.
2242     * @throws { BusinessError } 401 - Parameter error.
2243     * @throws { BusinessError } 201 - Permission denied.
2244     * @syscap SystemCapability.Communication.NetStack
2245     * @crossplatform
2246     * @since 10
2247     */
2248    connect(options: TCPConnectOptions, callback: AsyncCallback<void>): void;
2249
2250    /**
2251     * Sets up a connection to the specified IP address and port number.
2252     * @permission ohos.permission.INTERNET
2253     * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
2254     * @returns { Promise<void> } The promise returned by the function.
2255     * @throws { BusinessError } 401 - Parameter error.
2256     * @throws { BusinessError } 201 - Permission denied.
2257     * @syscap SystemCapability.Communication.NetStack
2258     * @since 7
2259     */
2260    /**
2261     * Sets up a connection to the specified IP address and port number.
2262     * @permission ohos.permission.INTERNET
2263     * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
2264     * @returns { Promise<void> } The promise returned by the function.
2265     * @throws { BusinessError } 401 - Parameter error.
2266     * @throws { BusinessError } 201 - Permission denied.
2267     * @syscap SystemCapability.Communication.NetStack
2268     * @crossplatform
2269     * @since 10
2270     */
2271    connect(options: TCPConnectOptions): Promise<void>;
2272
2273    /**
2274     * Sends data over a TCPSocket connection.
2275     * @permission ohos.permission.INTERNET
2276     * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
2277     * @param { AsyncCallback<void> } callback - the callback of send.
2278     * @throws { BusinessError } 401 - Parameter error.
2279     * @throws { BusinessError } 201 - Permission denied.
2280     * @syscap SystemCapability.Communication.NetStack
2281     * @since 7
2282     */
2283    /**
2284     * Sends data over a TCPSocket connection.
2285     * @permission ohos.permission.INTERNET
2286     * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
2287     * @param { AsyncCallback<void> } callback - the callback of send.
2288     * @throws { BusinessError } 401 - Parameter error.
2289     * @throws { BusinessError } 201 - Permission denied.
2290     * @syscap SystemCapability.Communication.NetStack
2291     * @crossplatform
2292     * @since 10
2293     */
2294    send(options: TCPSendOptions, callback: AsyncCallback<void>): void;
2295
2296    /**
2297     * Sends data over a TCPSocket connection.
2298     * @permission ohos.permission.INTERNET
2299     * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
2300     * @returns { Promise<void> } The promise returned by the function.
2301     * @throws { BusinessError } 401 - Parameter error.
2302     * @throws { BusinessError } 201 - Permission denied.
2303     * @syscap SystemCapability.Communication.NetStack
2304     * @since 7
2305     */
2306    /**
2307     * Sends data over a TCPSocket connection.
2308     * @permission ohos.permission.INTERNET
2309     * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
2310     * @returns { Promise<void> } The promise returned by the function.
2311     * @throws { BusinessError } 401 - Parameter error.
2312     * @throws { BusinessError } 201 - Permission denied.
2313     * @syscap SystemCapability.Communication.NetStack
2314     * @crossplatform
2315     * @since 10
2316     */
2317    send(options: TCPSendOptions): Promise<void>;
2318
2319    /**
2320     * Closes a TCPSocket connection.
2321     * @permission ohos.permission.INTERNET
2322     * @param { AsyncCallback<void> } callback - the callback of close.
2323     * @throws { BusinessError } 201 - Permission denied.
2324     * @syscap SystemCapability.Communication.NetStack
2325     * @since 7
2326     */
2327    /**
2328     * Closes a TCPSocket connection.
2329     * @permission ohos.permission.INTERNET
2330     * @param { AsyncCallback<void> } callback - the callback of close.
2331     * @throws { BusinessError } 201 - Permission denied.
2332     * @syscap SystemCapability.Communication.NetStack
2333     * @crossplatform
2334     * @since 10
2335     */
2336    close(callback: AsyncCallback<void>): void;
2337
2338    /**
2339     * Closes a TCPSocket connection.
2340     * @permission ohos.permission.INTERNET
2341     * @returns { Promise<void> } The promise returned by the function.
2342     * @throws { BusinessError } 201 - Permission denied.
2343     * @syscap SystemCapability.Communication.NetStack
2344     * @since 7
2345     */
2346    /**
2347     * Closes a TCPSocket connection.
2348     * @permission ohos.permission.INTERNET
2349     * @returns { Promise<void> } The promise returned by the function.
2350     * @throws { BusinessError } 201 - Permission denied.
2351     * @syscap SystemCapability.Communication.NetStack
2352     * @crossplatform
2353     * @since 10
2354     */
2355    close(): Promise<void>;
2356
2357    /**
2358     * Obtains the peer address of a TCPSocket connection.
2359     * @permission ohos.permission.INTERNET
2360     * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress}
2361     * @throws { BusinessError } 201 - Permission denied.
2362     * @syscap SystemCapability.Communication.NetStack
2363     * @since 7
2364     */
2365    /**
2366     * Obtains the peer address of a TCPSocket connection.
2367     * @permission ohos.permission.INTERNET
2368     * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress}
2369     * @throws { BusinessError } 201 - Permission denied.
2370     * @syscap SystemCapability.Communication.NetStack
2371     * @crossplatform
2372     * @since 10
2373     */
2374    getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
2375
2376    /**
2377     * Obtains the peer address of a TCPSocket connection.
2378     * @permission ohos.permission.INTERNET
2379     * @returns { Promise<NetAddress> } The promise returned by the function.
2380     * @throws { BusinessError } 201 - Permission denied.
2381     * @syscap SystemCapability.Communication.NetStack
2382     * @since 7
2383     */
2384    /**
2385     * Obtains the peer address of a TCPSocket connection.
2386     * @permission ohos.permission.INTERNET
2387     * @returns { Promise<NetAddress> } The promise returned by the function.
2388     * @throws { BusinessError } 201 - Permission denied.
2389     * @syscap SystemCapability.Communication.NetStack
2390     * @crossplatform
2391     * @since 10
2392     */
2393    getRemoteAddress(): Promise<NetAddress>;
2394
2395    /**
2396     * Obtains the status of the TCPSocket connection.
2397     * @permission ohos.permission.INTERNET
2398     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}
2399     * @throws { BusinessError } 201 - Permission denied.
2400     * @syscap SystemCapability.Communication.NetStack
2401     * @since 7
2402     */
2403    /**
2404     * Obtains the status of the TCPSocket connection.
2405     * @permission ohos.permission.INTERNET
2406     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}
2407     * @throws { BusinessError } 201 - Permission denied.
2408     * @syscap SystemCapability.Communication.NetStack
2409     * @crossplatform
2410     * @since 10
2411     */
2412    getState(callback: AsyncCallback<SocketStateBase>): void;
2413
2414    /**
2415     * Obtains the status of the TCPSocket connection.
2416     * @permission ohos.permission.INTERNET
2417     * @returns { Promise<SocketStateBase> } The promise returned by the function.
2418     * @throws { BusinessError } 201 - Permission denied.
2419     * @syscap SystemCapability.Communication.NetStack
2420     * @since 7
2421     */
2422    /**
2423     * Obtains the status of the TCPSocket connection.
2424     * @permission ohos.permission.INTERNET
2425     * @returns { Promise<SocketStateBase> } The promise returned by the function.
2426     * @throws { BusinessError } 201 - Permission denied.
2427     * @syscap SystemCapability.Communication.NetStack
2428     * @crossplatform
2429     * @since 10
2430     */
2431    getState(): Promise<SocketStateBase>;
2432
2433    /**
2434     * Obtains the file descriptor of the TCPSocket connection.
2435     * @param { AsyncCallback<number> } callback - The callback returns the file descriptor of the TCPSocket connection.
2436     * @syscap SystemCapability.Communication.NetStack
2437     * @since 10
2438     */
2439    getSocketFd(callback: AsyncCallback<number>): void;
2440
2441    /**
2442     * Obtains the file descriptor of the TCPSocket connection.
2443     * @returns { Promise<number> } The promise returns the file descriptor of the TCPSocket connection.
2444     * @syscap SystemCapability.Communication.NetStack
2445     * @since 10
2446     */
2447    getSocketFd(): Promise<number>;
2448
2449    /**
2450     * Sets other attributes of the TCPSocket connection.
2451     * @permission ohos.permission.INTERNET
2452     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2453     * @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
2454     * @throws { BusinessError } 401 - Parameter error.
2455     * @throws { BusinessError } 201 - Permission denied.
2456     * @syscap SystemCapability.Communication.NetStack
2457     * @since 7
2458     */
2459    /**
2460     * Sets other attributes of the TCPSocket connection.
2461     * @permission ohos.permission.INTERNET
2462     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2463     * @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
2464     * @throws { BusinessError } 401 - Parameter error.
2465     * @throws { BusinessError } 201 - Permission denied.
2466     * @syscap SystemCapability.Communication.NetStack
2467     * @crossplatform
2468     * @since 10
2469     */
2470    setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
2471
2472    /**
2473     * Sets other attributes of the TCPSocket connection.
2474     * @permission ohos.permission.INTERNET
2475     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2476     * @returns { Promise<void> } The promise returned by the function.
2477     * @throws { BusinessError } 401 - Parameter error.
2478     * @throws { BusinessError } 201 - Permission denied.
2479     * @syscap SystemCapability.Communication.NetStack
2480     * @since 7
2481     */
2482    /**
2483     * Sets other attributes of the TCPSocket connection.
2484     * @permission ohos.permission.INTERNET
2485     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2486     * @returns { Promise<void> } The promise returned by the function.
2487     * @throws { BusinessError } 401 - Parameter error.
2488     * @throws { BusinessError } 201 - Permission denied.
2489     * @syscap SystemCapability.Communication.NetStack
2490     * @crossplatform
2491     * @since 10
2492     */
2493    setExtraOptions(options: TCPExtraOptions): Promise<void>;
2494
2495    /**
2496     * Obtains the local address of a TCPSocket connection.
2497     * @returns { Promise<NetAddress> } The promise returned by the function.
2498     * @throws { BusinessError } 2300002 - System internal error.
2499     * @throws { BusinessError } 2301009 - Bad file descriptor.
2500     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2501     * @syscap SystemCapability.Communication.NetStack
2502     * @since 12
2503     */
2504    getLocalAddress(): Promise<NetAddress>;
2505
2506    /**
2507     * Listens for message receiving events of the TCPSocket connection.
2508     * @param { 'message' } type - Indicates Event name.
2509     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2510     * @syscap SystemCapability.Communication.NetStack
2511     * @since 7
2512     */
2513    /**
2514     * Listens for message receiving events of the TCPSocket connection.
2515     * @param { 'message' } type Indicates Event name.
2516     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2517     * @syscap SystemCapability.Communication.NetStack
2518     * @crossplatform
2519     * @since 10
2520     */
2521    /**
2522     * Listens for message receiving events of the TCPSocket connection.
2523     * @param { 'message' } type Indicates Event name.
2524     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
2525     * @syscap SystemCapability.Communication.NetStack
2526     * @crossplatform
2527     * @since 11
2528     */
2529    on(type: 'message', callback: Callback<SocketMessageInfo>): void;
2530
2531    /**
2532     * Cancels listening for message receiving events of the TCPSocket connection.
2533     * @param { 'message' } type Indicates Event name.
2534     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2535     * @syscap SystemCapability.Communication.NetStack
2536     * @since 7
2537     */
2538    /**
2539     * Cancels listening for message receiving events of the TCPSocket connection.
2540     * @param { 'message' } type Indicates Event name.
2541     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2542     * @syscap SystemCapability.Communication.NetStack
2543     * @crossplatform
2544     * @since 10
2545     */
2546    /**
2547     * Cancels listening for message receiving events of the TCPSocket connection.
2548     * @param { 'message' } type Indicates Event name.
2549     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
2550     * @syscap SystemCapability.Communication.NetStack
2551     * @crossplatform
2552     * @since 11
2553     */
2554    off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
2555
2556
2557    /**
2558     * Listens for connection or close events of the TCPSocket connection.
2559     * @param { 'connect' | 'close' } type - Indicates Event name.
2560     * @param { Callback<void> } callback - the callback used to return the result.
2561     * @syscap SystemCapability.Communication.NetStack
2562     * @since 7
2563     */
2564    /**
2565     * Listens for connection or close events of the TCPSocket connection.
2566     * @param { 'connect' | 'close' } type - Indicates Event name.
2567     * @param { Callback<void> } callback - the callback used to return the result.
2568     * @syscap SystemCapability.Communication.NetStack
2569     * @crossplatform
2570     * @since 10
2571     */
2572    on(type: 'connect' | 'close', callback: Callback<void>): void;
2573
2574    /**
2575     * Cancels listening for connection or close events of the TCPSocket connection.
2576     * @param { 'connect' | 'close' } type - Indicates Event name.
2577     * @param { Callback<void> } callback - the callback used to return the result.
2578     * @syscap SystemCapability.Communication.NetStack
2579     * @since 7
2580     */
2581    /**
2582     * Cancels listening for connection or close events of the TCPSocket connection.
2583     * @param { 'connect' | 'close' } type - Indicates Event name.
2584     * @param { Callback<void> } callback - the callback used to return the result.
2585     * @syscap SystemCapability.Communication.NetStack
2586     * @crossplatform
2587     * @since 10
2588     */
2589    off(type: 'connect' | 'close', callback?: Callback<void>): void;
2590
2591    /**
2592     * Listens for error events of the TCPSocket connection.
2593     * @param { 'error' } type - Indicates Event name.
2594     * @param { ErrorCallback } callback - the callback used to return the result.
2595     * @syscap SystemCapability.Communication.NetStack
2596     * @since 7
2597     */
2598    /**
2599     * Listens for error events of the TCPSocket connection.
2600     * @param { 'error' } type - Indicates Event name.
2601     * @param { ErrorCallback } callback - the callback used to return the result.
2602     * @syscap SystemCapability.Communication.NetStack
2603     * @crossplatform
2604     * @since 10
2605     */
2606    on(type: 'error', callback: ErrorCallback): void;
2607
2608    /**
2609     * Cancels listening for error events of the TCPSocket connection.
2610     * @param { 'error' } type - Indicates Event name.
2611     * @param { ErrorCallback } callback - the callback used to return the result.
2612     * @syscap SystemCapability.Communication.NetStack
2613     * @since 7
2614     */
2615    /**
2616     * Cancels listening for error events of the TCPSocket connection.
2617     * @param { 'error' } type - Indicates Event name.
2618     * @param { ErrorCallback } callback - the callback used to return the result.
2619     * @syscap SystemCapability.Communication.NetStack
2620     * @crossplatform
2621     * @since 10
2622     */
2623    off(type: 'error', callback?: ErrorCallback): void;
2624  }
2625
2626  /**
2627   * Defines a TLSSocket connection.
2628   * @interface TLSSocket
2629   * @syscap SystemCapability.Communication.NetStack
2630   * @since 9
2631   */
2632  /**
2633   * Defines a TLSSocket connection.
2634   * @interface TLSSocket
2635   * @syscap SystemCapability.Communication.NetStack
2636   * @crossplatform
2637   * @since 10
2638   */
2639  export interface TLSSocket {
2640    /**
2641     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2642     * @permission ohos.permission.INTERNET
2643     * @param { NetAddress } address - Destination address. {@link NetAddress}
2644     * @param { AsyncCallback<void> } callback - the callback of bind.
2645     * @throws { BusinessError } 401 - Parameter error.
2646     * @throws { BusinessError } 201 - Permission denied.
2647     * @throws { BusinessError } 2303198 - Address already in use.
2648     * @throws { BusinessError } 2300002 - System internal error.
2649     * @syscap SystemCapability.Communication.NetStack
2650     * @since 9
2651     */
2652    /**
2653     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2654     * @permission ohos.permission.INTERNET
2655     * @param { NetAddress } address - Destination address. {@link NetAddress}
2656     * @param { AsyncCallback<void> } callback - the callback of bind.
2657     * @throws { BusinessError } 401 - Parameter error.
2658     * @throws { BusinessError } 201 - Permission denied.
2659     * @throws { BusinessError } 2303198 - Address already in use.
2660     * @throws { BusinessError } 2300002 - System internal error.
2661     * @syscap SystemCapability.Communication.NetStack
2662     * @crossplatform
2663     * @since 10
2664     */
2665    bind(address: NetAddress, callback: AsyncCallback<void>): void;
2666
2667    /**
2668     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2669     * @permission ohos.permission.INTERNET
2670     * @param { NetAddress } address - Destination address. {@link NetAddress}
2671     * @returns { Promise<void> } The promise returned by the function.
2672     * @throws { BusinessError } 401 - Parameter error.
2673     * @throws { BusinessError } 201 - Permission denied.
2674     * @throws { BusinessError } 2303198 - Address already in use.
2675     * @throws { BusinessError } 2300002 - System internal error.
2676     * @syscap SystemCapability.Communication.NetStack
2677     * @since 9
2678     */
2679    /**
2680     * Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
2681     * @permission ohos.permission.INTERNET
2682     * @param { NetAddress } address - Destination address. {@link NetAddress}
2683     * @returns { Promise<void> } The promise returned by the function.
2684     * @throws { BusinessError } 401 - Parameter error.
2685     * @throws { BusinessError } 201 - Permission denied.
2686     * @throws { BusinessError } 2303198 - Address already in use.
2687     * @throws { BusinessError } 2300002 - System internal error.
2688     * @syscap SystemCapability.Communication.NetStack
2689     * @crossplatform
2690     * @since 10
2691     */
2692    bind(address: NetAddress): Promise<void>;
2693
2694    /**
2695     * Obtains the peer address of a TLSSocket connection.
2696     * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress.
2697     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2698     * @throws { BusinessError } 2300002 - System internal error.
2699     * @syscap SystemCapability.Communication.NetStack
2700     * @since 9
2701     */
2702    /**
2703     * Obtains the peer address of a TLSSocket connection.
2704     * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress.
2705     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2706     * @throws { BusinessError } 2300002 - System internal error.
2707     * @syscap SystemCapability.Communication.NetStack
2708     * @crossplatform
2709     * @since 10
2710     */
2711    getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
2712
2713    /**
2714     * Obtains the peer address of a TLSSocket connection.
2715     * @returns { Promise<NetAddress> } The promise returned by the function.
2716     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2717     * @throws { BusinessError } 2300002 - System internal error.
2718     * @syscap SystemCapability.Communication.NetStack
2719     * @since 9
2720     */
2721    /**
2722     * Obtains the peer address of a TLSSocket connection.
2723     * @returns { Promise<NetAddress> } The promise returned by the function.
2724     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2725     * @throws { BusinessError } 2300002 - System internal error.
2726     * @syscap SystemCapability.Communication.NetStack
2727     * @crossplatform
2728     * @since 10
2729     */
2730    getRemoteAddress(): Promise<NetAddress>;
2731
2732    /**
2733     * Obtains the status of the TLSSocket connection.
2734     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState.
2735     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2736     * @throws { BusinessError } 2300002 - System internal error.
2737     * @syscap SystemCapability.Communication.NetStack
2738     * @since 9
2739     */
2740    /**
2741     * Obtains the status of the TLSSocket connection.
2742     * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState.
2743     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2744     * @throws { BusinessError } 2300002 - System internal error.
2745     * @syscap SystemCapability.Communication.NetStack
2746     * @crossplatform
2747     * @since 10
2748     */
2749    getState(callback: AsyncCallback<SocketStateBase>): void;
2750
2751    /**
2752     * Obtains the status of the TLSSocket connection.
2753     * @returns { Promise<SocketStateBase> } The promise returned by the function.
2754     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2755     * @throws { BusinessError } 2300002 - System internal error.
2756     * @syscap SystemCapability.Communication.NetStack
2757     * @since 9
2758     */
2759    /**
2760     * Obtains the status of the TLSSocket connection.
2761     * @returns { Promise<SocketStateBase> } The promise returned by the function.
2762     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2763     * @throws { BusinessError } 2300002 - System internal error.
2764     * @syscap SystemCapability.Communication.NetStack
2765     * @crossplatform
2766     * @since 10
2767     */
2768    getState(): Promise<SocketStateBase>;
2769
2770    /**
2771     * Sets other attributes of the TLSSocket connection.
2772     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2773     * @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
2774     * @throws { BusinessError } 401 - Parameter error.
2775     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2776     * @throws { BusinessError } 2300002 - System internal error.
2777     * @syscap SystemCapability.Communication.NetStack
2778     * @since 9
2779     */
2780    /**
2781     * Sets other attributes of the TLSSocket connection.
2782     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2783     * @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
2784     * @throws { BusinessError } 401 - Parameter error.
2785     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2786     * @throws { BusinessError } 2300002 - System internal error.
2787     * @syscap SystemCapability.Communication.NetStack
2788     * @crossplatform
2789     * @since 10
2790     */
2791    setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
2792
2793    /**
2794     * Sets other attributes of the TLSSocket connection.
2795     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2796     * @returns { Promise<void> } The promise returned by the function.
2797     * @throws { BusinessError } 401 - Parameter error.
2798     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2799     * @throws { BusinessError } 2300002 - System internal error.
2800     * @syscap SystemCapability.Communication.NetStack
2801     * @since 9
2802     */
2803    /**
2804     * Sets other attributes of the TLSSocket connection.
2805     * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
2806     * @returns { Promise<void> } The promise returned by the function.
2807     * @throws { BusinessError } 401 - Parameter error.
2808     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2809     * @throws { BusinessError } 2300002 - System internal error.
2810     * @syscap SystemCapability.Communication.NetStack
2811     * @crossplatform
2812     * @since 10
2813     */
2814    setExtraOptions(options: TCPExtraOptions): Promise<void>;
2815
2816    /**
2817     * Obtains the local address of a TLSSocket connection.
2818     * @returns { Promise<NetAddress> } The promise returned by the function.
2819     * @throws { BusinessError } 2300002 - System internal error.
2820     * @throws { BusinessError } 2301009 - Bad file descriptor.
2821     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
2822     * @syscap SystemCapability.Communication.NetStack
2823     * @since 12
2824     */
2825    getLocalAddress(): Promise<NetAddress>;
2826
2827    /**
2828     * Listens for message receiving events of the TLSSocket connection.
2829     * @param { 'message' } type - Indicates Event name.
2830     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2831     * @throws { BusinessError } 401 - Parameter error.
2832     * @syscap SystemCapability.Communication.NetStack
2833     * @since 9
2834     */
2835    /**
2836     * Listens for message receiving events of the TLSSocket connection.
2837     * @param { 'message' } type Indicates Event name.
2838     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2839     * @throws { BusinessError } 401 - Parameter error.
2840     * @syscap SystemCapability.Communication.NetStack
2841     * @crossplatform
2842     * @since 10
2843     */
2844    /**
2845     * Listens for message receiving events of the TLSSocket connection.
2846     * @param { 'message' } type Indicates Event name.
2847     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
2848     * @throws { BusinessError } 401 - Parameter error.
2849     * @syscap SystemCapability.Communication.NetStack
2850     * @crossplatform
2851     * @since 11
2852     */
2853    on(type: 'message', callback: Callback<SocketMessageInfo>): void;
2854
2855    /**
2856     * Cancels listening for message receiving events of the TLSSocket connection.
2857     * @param { 'message' } type - Indicates Event name.
2858     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2859     * @throws { BusinessError } 401 - Parameter error.
2860     * @syscap SystemCapability.Communication.NetStack
2861     * @since 9
2862     */
2863    /**
2864     * Cancels listening for message receiving events of the TLSSocket connection.
2865     * @param { 'message' } type Indicates Event name.
2866     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
2867     * @throws { BusinessError } 401 - Parameter error.
2868     * @syscap SystemCapability.Communication.NetStack
2869     * @crossplatform
2870     * @since 10
2871     */
2872    /**
2873     * Cancels listening for message receiving events of the TLSSocket connection.
2874     * @param { 'message' } type Indicates Event name.
2875     * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
2876     * @throws { BusinessError } 401 - Parameter error.
2877     * @syscap SystemCapability.Communication.NetStack
2878     * @crossplatform
2879     * @since 11
2880     */
2881    off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
2882
2883    /**
2884     * Listens for connection or close events of the TLSSocket connection.
2885     * @param { 'connect' | 'close' } type - Indicates Event name.
2886     * @param {Callback<void> } callback - the callback used to return the result.
2887     * @throws { BusinessError } 401 - Parameter error.
2888     * @syscap SystemCapability.Communication.NetStack
2889     * @since 9
2890     */
2891    /**
2892     * Listens for connection or close events of the TLSSocket connection.
2893     * @param { 'connect' | 'close' } type - Indicates Event name.
2894     * @param {Callback<void> } callback - the callback used to return the result.
2895     * @throws { BusinessError } 401 - Parameter error.
2896     * @syscap SystemCapability.Communication.NetStack
2897     * @crossplatform
2898     * @since 10
2899     */
2900    on(type: 'connect' | 'close', callback: Callback<void>): void;
2901
2902    /**
2903     * Cancels listening for connection or close events of the TLSSocket connection.
2904     * @param { 'connect' | 'close' } type - Indicates Event name.
2905     * @param {Callback<void> } callback - the callback used to return the result.
2906     * @throws { BusinessError } 401 - Parameter error.
2907     * @syscap SystemCapability.Communication.NetStack
2908     * @since 9
2909     */
2910    /**
2911     * Cancels listening for connection or close events of the TLSSocket connection.
2912     * @param { 'connect' | 'close' } type - Indicates Event name.
2913     * @param {Callback<void> } callback - the callback used to return the result.
2914     * @throws { BusinessError } 401 - Parameter error.
2915     * @syscap SystemCapability.Communication.NetStack
2916     * @crossplatform
2917     * @since 10
2918     */
2919    off(type: 'connect' | 'close', callback?: Callback<void>): void;
2920
2921    /**
2922     * Listens for error events of the TLSSocket connection.
2923     * @param { 'error' } type - Indicates Event name.
2924     * @param { ErrorCallback } callback - the callback used to return the result.
2925     * @throws { BusinessError } 401 - Parameter error.
2926     * @syscap SystemCapability.Communication.NetStack
2927     * @since 9
2928     */
2929    /**
2930     * Listens for error events of the TLSSocket connection.
2931     * @param { 'error' } type - Indicates Event name.
2932     * @param { ErrorCallback } callback - the callback used to return the result.
2933     * @throws { BusinessError } 401 - Parameter error.
2934     * @syscap SystemCapability.Communication.NetStack
2935     * @crossplatform
2936     * @since 10
2937     */
2938    on(type: 'error', callback: ErrorCallback): void;
2939
2940    /**
2941     * Cancels listening for error events of the TLSSocket connection.
2942     * @param { 'error' } type - Indicates Event name.
2943     * @param { ErrorCallback } callback - the callback used to return the result.
2944     * @throws { BusinessError } 401 - Parameter error.
2945     * @syscap SystemCapability.Communication.NetStack
2946     * @since 9
2947     */
2948    /**
2949     * Cancels listening for error events of the TLSSocket connection.
2950     * @param { 'error' } type - Indicates Event name.
2951     * @param { ErrorCallback } callback - the callback used to return the result.
2952     * @throws { BusinessError } 401 - Parameter error.
2953     * @syscap SystemCapability.Communication.NetStack
2954     * @crossplatform
2955     * @since 10
2956     */
2957    off(type: 'error', callback?: ErrorCallback): void;
2958
2959    /**
2960     * Returns an object representing a local certificate.
2961     * @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate.
2962     * @throws { BusinessError } 2303501 - SSL is null.
2963     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
2964     * @throws { BusinessError } 2300002 - System internal error.
2965     * @syscap SystemCapability.Communication.NetStack
2966     * @since 9
2967     */
2968    /**
2969     * Returns an object representing a local certificate.
2970     * @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate.
2971     * @throws { BusinessError } 2303501 - SSL is null.
2972     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
2973     * @throws { BusinessError } 2300002 - System internal error.
2974     * @syscap SystemCapability.Communication.NetStack
2975     * @crossplatform
2976     * @since 10
2977     */
2978    getCertificate(callback: AsyncCallback<X509CertRawData>): void;
2979
2980    /**
2981     * Returns an object representing a local certificate.
2982     * @returns { Promise<X509CertRawData> } The promise returned by the function.
2983     * @throws { BusinessError } 2303501 - SSL is null.
2984     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
2985     * @throws { BusinessError } 2300002 - System internal error.
2986     * @syscap SystemCapability.Communication.NetStack
2987     * @since 9
2988     */
2989    /**
2990     * Returns an object representing a local certificate.
2991     * @returns { Promise<X509CertRawData> } The promise returned by the function.
2992     * @throws { BusinessError } 2303501 - SSL is null.
2993     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
2994     * @throws { BusinessError } 2300002 - System internal error.
2995     * @syscap SystemCapability.Communication.NetStack
2996     * @crossplatform
2997     * @since 10
2998     */
2999    getCertificate(): Promise<X509CertRawData>;
3000
3001    /**
3002     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
3003     * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
3004     * It only contains the peer's certificate.
3005     * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate.
3006     * @throws { BusinessError } 2303501 - SSL is null.
3007     * @throws { BusinessError } 2300002 - System internal error.
3008     * @syscap SystemCapability.Communication.NetStack
3009     * @since 9
3010     */
3011    /**
3012     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
3013     * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
3014     * It only contains the peer's certificate.
3015     * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate.
3016     * @throws { BusinessError } 2303501 - SSL is null.
3017     * @throws { BusinessError } 2300002 - System internal error.
3018     * @syscap SystemCapability.Communication.NetStack
3019     * @crossplatform
3020     * @since 10
3021     */
3022    getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void;
3023
3024    /**
3025     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
3026     * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
3027     * It only contains the peer's certificate.
3028     * @returns { Promise<X509CertRawData> } The promise returned by the function.
3029     * @throws { BusinessError } 2303501 - SSL is null.
3030     * @throws { BusinessError } 2300002 - System internal error.
3031     * @syscap SystemCapability.Communication.NetStack
3032     * @since 9
3033     */
3034    /**
3035     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
3036     * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
3037     * It only contains the peer's certificate.
3038     * @returns { Promise<X509CertRawData> } The promise returned by the function.
3039     * @throws { BusinessError } 2303501 - SSL is null.
3040     * @throws { BusinessError } 2300002 - System internal error.
3041     * @syscap SystemCapability.Communication.NetStack
3042     * @crossplatform
3043     * @since 10
3044     */
3045    getRemoteCertificate(): Promise<X509CertRawData>;
3046
3047    /**
3048     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
3049     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
3050     * Server sockets or disconnected client sockets will return a value of null.
3051     * @param { AsyncCallback<string> } callback - the callback of getProtocol.
3052     * @throws { BusinessError } 2303501 - SSL is null.
3053     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3054     * @throws { BusinessError } 2300002 - System internal error.
3055     * @syscap SystemCapability.Communication.NetStack
3056     * @since 9
3057     */
3058    /**
3059     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
3060     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
3061     * Server sockets or disconnected client sockets will return a value of null.
3062     * @param { AsyncCallback<string> } callback - the callback of getProtocol.
3063     * @throws { BusinessError } 2303501 - SSL is null.
3064     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3065     * @throws { BusinessError } 2300002 - System internal error.
3066     * @syscap SystemCapability.Communication.NetStack
3067     * @crossplatform
3068     * @since 10
3069     */
3070    getProtocol(callback: AsyncCallback<string>): void;
3071
3072    /**
3073     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
3074     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
3075     * Server sockets or disconnected client sockets will return a value of null.
3076     * @returns { Promise<string> } The promise returned by the function.
3077     * @throws { BusinessError } 2303501 - SSL is null.
3078     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3079     * @throws { BusinessError } 2300002 - System internal error.
3080     * @syscap SystemCapability.Communication.NetStack
3081     * @since 9
3082     */
3083    /**
3084     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
3085     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
3086     * Server sockets or disconnected client sockets will return a value of null.
3087     * @returns { Promise<string> } The promise returned by the function.
3088     * @throws { BusinessError } 2303501 - SSL is null.
3089     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3090     * @throws { BusinessError } 2300002 - System internal error.
3091     * @syscap SystemCapability.Communication.NetStack
3092     * @crossplatform
3093     * @since 10
3094     */
3095    getProtocol(): Promise<string>;
3096
3097    /**
3098     * Returns a list containing the negotiated cipher suite information.
3099     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
3100     * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite.
3101     * @throws { BusinessError } 2303501 - SSL is null.
3102     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3103     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3104     * @throws { BusinessError } 2300002 - System internal error.
3105     * @syscap SystemCapability.Communication.NetStack
3106     * @since 9
3107     */
3108    /**
3109     * Returns a list containing the negotiated cipher suite information.
3110     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
3111     * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite.
3112     * @throws { BusinessError } 2303501 - SSL is null.
3113     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3114     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3115     * @throws { BusinessError } 2300002 - System internal error.
3116     * @syscap SystemCapability.Communication.NetStack
3117     * @crossplatform
3118     * @since 10
3119     */
3120    getCipherSuite(callback: AsyncCallback<Array<string>>): void;
3121
3122    /**
3123     * Returns a list containing the negotiated cipher suite information.
3124     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
3125     * @returns { Promise<Array<string>> } The promise returned by the function.
3126     * @throws { BusinessError } 2303501 - SSL is null.
3127     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3128     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3129     * @throws { BusinessError } 2300002 - System internal error.
3130     * @syscap SystemCapability.Communication.NetStack
3131     * @since 9
3132     */
3133    /**
3134     * Returns a list containing the negotiated cipher suite information.
3135     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
3136     * @returns { Promise<Array<string>> } The promise returned by the function.
3137     * @throws { BusinessError } 2303501 - SSL is null.
3138     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3139     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3140     * @throws { BusinessError } 2300002 - System internal error.
3141     * @syscap SystemCapability.Communication.NetStack
3142     * @crossplatform
3143     * @since 10
3144     */
3145    getCipherSuite(): Promise<Array<string>>;
3146
3147    /**
3148     * <p>The list of signature algorithms shared between the server and the client,
3149     * in descending order of priority.</p>
3150     * @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
3151     * @throws { BusinessError } 2303501 - SSL is null.
3152     * @throws { BusinessError } 2300002 - System internal error.
3153     * @syscap SystemCapability.Communication.NetStack
3154     * @since 9
3155     */
3156    /**
3157     * <p>The list of signature algorithms shared between the server and the client,
3158     * in descending order of priority.</p>
3159     * @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
3160     * @throws { BusinessError } 2303501 - SSL is null.
3161     * @throws { BusinessError } 2300002 - System internal error.
3162     * @syscap SystemCapability.Communication.NetStack
3163     * @crossplatform
3164     * @since 10
3165     */
3166    getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void;
3167
3168    /**
3169     * <p>The list of signature algorithms shared between the server and the client,
3170     * in descending order of priority.</p>
3171     * @returns { Promise<Array<string>> } The promise returned by the function.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
3172     * @throws { BusinessError } 2303501 - SSL is null.
3173     * @throws { BusinessError } 2300002 - System internal error.
3174     * @syscap SystemCapability.Communication.NetStack
3175     * @since 9
3176     */
3177    /**
3178     * <p>The list of signature algorithms shared between the server and the client,
3179     * in descending order of priority.</p>
3180     * @returns { Promise<Array<string>> } The promise returned by the function.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
3181     * @throws { BusinessError } 2303501 - SSL is null.
3182     * @throws { BusinessError } 2300002 - System internal error.
3183     * @syscap SystemCapability.Communication.NetStack
3184     * @crossplatform
3185     * @since 10
3186     */
3187    getSignatureAlgorithms(): Promise<Array<string>>;
3188
3189    /**
3190     * Sets up a connection to the specified IP address and port number.
3191     * Only TCP is supported.
3192     * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
3193     * @param { AsyncCallback<void> } callback - the callback of connect.
3194     * @throws { BusinessError } 401 - Parameter error.
3195     * @throws { BusinessError } 2303104 - Interrupted system call.
3196     * @throws { BusinessError } 2303109 - Bad file number.
3197     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3198     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3199     * @throws { BusinessError } 2303191 - Incorrect socket protocol type.
3200     * @throws { BusinessError } 2303198 - Address already in use.
3201     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3202     * @throws { BusinessError } 2303210 - Connection timed out.
3203     * @throws { BusinessError } 2303501 - SSL is null.
3204     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3205     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3206     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3207     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3208     * @throws { BusinessError } 2300002 - System internal error.
3209     * @syscap SystemCapability.Communication.NetStack
3210     * @since 9
3211     */
3212    /**
3213     * Sets up a connection to the specified IP address and port number.
3214     * Only TCP is supported.
3215     * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
3216     * @param { AsyncCallback<void> } callback - the callback of connect.
3217     * @throws { BusinessError } 401 - Parameter error.
3218     * @throws { BusinessError } 2303104 - Interrupted system call.
3219     * @throws { BusinessError } 2303109 - Bad file number.
3220     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3221     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3222     * @throws { BusinessError } 2303191 - Incorrect socket protocol type.
3223     * @throws { BusinessError } 2303198 - Address already in use.
3224     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3225     * @throws { BusinessError } 2303210 - Connection timed out.
3226     * @throws { BusinessError } 2303501 - SSL is null.
3227     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3228     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3229     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3230     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3231     * @throws { BusinessError } 2300002 - System internal error.
3232     * @syscap SystemCapability.Communication.NetStack
3233     * @crossplatform
3234     * @since 10
3235     */
3236    connect(options: TLSConnectOptions, callback: AsyncCallback<void>): void;
3237
3238    /**
3239     * Sets up a connection to the specified IP address and port number.
3240     * Only TCP is supported.
3241     * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
3242     * @returns { Promise<void> } The promise returned by the function.
3243     * @throws { BusinessError } 401 - Parameter error.
3244     * @throws { BusinessError } 2303104 - Interrupted system call.
3245     * @throws { BusinessError } 2303109 - Bad file number.
3246     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3247     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3248     * @throws { BusinessError } 2303191 - Incorrect socket protocol type.
3249     * @throws { BusinessError } 2303198 - Address already in use.
3250     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3251     * @throws { BusinessError } 2303210 - Connection timed out.
3252     * @throws { BusinessError } 2303501 - SSL is null.
3253     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3254     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3255     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3256     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3257     * @throws { BusinessError } 2300002 - System internal error.
3258     * @syscap SystemCapability.Communication.NetStack
3259     * @since 9
3260     */
3261    /**
3262     * Sets up a connection to the specified IP address and port number.
3263     * Only TCP is supported.
3264     * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
3265     * @returns { Promise<void> } The promise returned by the function.
3266     * @throws { BusinessError } 401 - Parameter error.
3267     * @throws { BusinessError } 2303104 - Interrupted system call.
3268     * @throws { BusinessError } 2303109 - Bad file number.
3269     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3270     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3271     * @throws { BusinessError } 2303191 - Incorrect socket protocol type.
3272     * @throws { BusinessError } 2303198 - Address already in use.
3273     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3274     * @throws { BusinessError } 2303210 - Connection timed out.
3275     * @throws { BusinessError } 2303501 - SSL is null.
3276     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
3277     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3278     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3279     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3280     * @throws { BusinessError } 2300002 - System internal error.
3281     * @syscap SystemCapability.Communication.NetStack
3282     * @crossplatform
3283     * @since 10
3284     */
3285    connect(options: TLSConnectOptions): Promise<void>;
3286
3287    /**
3288     * Sends data over a TLSSocket connection.
3289     * @param { string } data - Parameters for sending data {@link string}.
3290     * @param { AsyncCallback<void> } callback - the callback of send.
3291     * @throws { BusinessError } 401 - Parameter error.
3292     * @throws { BusinessError } 2303501 - SSL is null.
3293     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3294     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3295     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3296     * @throws { BusinessError } 2300002 - System internal error.
3297     * @syscap SystemCapability.Communication.NetStack
3298     * @since 9
3299     */
3300    /**
3301     * Sends data over a TLSSocket connection.
3302     * @param { string } data - Parameters for sending data {@link string}.
3303     * @param { AsyncCallback<void> } callback - the callback of send.
3304     * @throws { BusinessError } 401 - Parameter error.
3305     * @throws { BusinessError } 2303501 - SSL is null.
3306     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3307     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3308     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3309     * @throws { BusinessError } 2300002 - System internal error.
3310     * @syscap SystemCapability.Communication.NetStack
3311     * @crossplatform
3312     * @since 10
3313     */
3314    /**
3315     * Sends data over a TLSSocket connection.
3316     * @param { string | ArrayBuffer } data - Parameters for sending data.
3317     * @param { AsyncCallback<void> } callback - the callback of send.
3318     * @throws { BusinessError } 401 - Parameter error.
3319     * @throws { BusinessError } 2303501 - SSL is null.
3320     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3321     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3322     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3323     * @throws { BusinessError } 2300002 - System internal error.
3324     * @syscap SystemCapability.Communication.NetStack
3325     * @crossplatform
3326     * @since 12
3327     */
3328    send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void;
3329
3330    /**
3331     * Sends data over a TLSSocket connection.
3332     * @param { string } data - Parameters for sending data {@link string}.
3333     * @returns { Promise<void> } The promise returned by the function.
3334     * @throws { BusinessError } 401 - Parameter error.
3335     * @throws { BusinessError } 2303501 - SSL is null.
3336     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3337     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3338     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3339     * @throws { BusinessError } 2300002 - System internal error.
3340     * @syscap SystemCapability.Communication.NetStack
3341     * @since 9
3342     */
3343    /**
3344     * Sends data over a TLSSocket connection.
3345     * @param { string } data - Parameters for sending data {@link string}.
3346     * @returns { Promise<void> } The promise returned by the function.
3347     * @throws { BusinessError } 401 - Parameter error.
3348     * @throws { BusinessError } 2303501 - SSL is null.
3349     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3350     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3351     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3352     * @throws { BusinessError } 2300002 - System internal error.
3353     * @syscap SystemCapability.Communication.NetStack
3354     * @crossplatform
3355     * @since 10
3356     */
3357    /**
3358     * Sends data over a TLSSocket connection.
3359     * @param { string | ArrayBuffer } data - Parameters for sending data.
3360     * @returns { Promise<void> } The promise returned by the function.
3361     * @throws { BusinessError } 401 - Parameter error.
3362     * @throws { BusinessError } 2303501 - SSL is null.
3363     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
3364     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3365     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3366     * @throws { BusinessError } 2300002 - System internal error.
3367     * @syscap SystemCapability.Communication.NetStack
3368     * @crossplatform
3369     * @since 12
3370     */
3371    send(data: string | ArrayBuffer): Promise<void>;
3372
3373    /**
3374     * Closes a TLSSocket connection
3375     * @param { AsyncCallback<void> } callback - the callback of close.
3376     * @throws { BusinessError } 401 - Parameter error.
3377     * @throws { BusinessError } 2303501 - SSL is null.
3378     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3379     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3380     * @throws { BusinessError } 2300002 - System internal error.
3381     * @syscap SystemCapability.Communication.NetStack
3382     * @since 9
3383     */
3384    /**
3385     * Closes a TLSSocket connection
3386     * @param { AsyncCallback<void> } callback - the callback of close.
3387     * @throws { BusinessError } 401 - Parameter error.
3388     * @throws { BusinessError } 2303501 - SSL is null.
3389     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3390     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3391     * @throws { BusinessError } 2300002 - System internal error.
3392     * @syscap SystemCapability.Communication.NetStack
3393     * @crossplatform
3394     * @since 10
3395     */
3396    close(callback: AsyncCallback<void>): void;
3397
3398    /**
3399     * Closes a TLSSocket connection
3400     * @returns { Promise<void> } The promise returned by the function.
3401     * @throws { BusinessError } 401 - Parameter error.
3402     * @throws { BusinessError } 2303501 - SSL is null.
3403     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3404     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3405     * @throws { BusinessError } 2300002 - System internal error.
3406     * @syscap SystemCapability.Communication.NetStack
3407     * @since 9
3408     */
3409    /**
3410     * Closes a TLSSocket connection
3411     * @returns { Promise<void> } The promise returned by the function.
3412     * @throws { BusinessError } 401 - Parameter error.
3413     * @throws { BusinessError } 2303501 - SSL is null.
3414     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
3415     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
3416     * @throws { BusinessError } 2300002 - System internal error.
3417     * @syscap SystemCapability.Communication.NetStack
3418     * @crossplatform
3419     * @since 10
3420     */
3421    close(): Promise<void>;
3422  }
3423
3424  /**
3425   * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional.
3426   * @interface TLSSecureOptions
3427   * @syscap SystemCapability.Communication.NetStack
3428   * @since 9
3429   */
3430  /**
3431   * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional.
3432   * @interface TLSSecureOptions
3433   * @syscap SystemCapability.Communication.NetStack
3434   * @crossplatform
3435   * @since 10
3436   */
3437  export interface TLSSecureOptions {
3438    /**
3439     * Certificate used to verify the identity of the server
3440     * @type {string | Array<string>}
3441     * @syscap SystemCapability.Communication.NetStack
3442     * @since 9
3443     */
3444    /**
3445     * Certificate used to verify the identity of the server.
3446     * @type {string | Array<string>}
3447     * @syscap SystemCapability.Communication.NetStack
3448     * @crossplatform
3449     * @since 10
3450     */
3451    /**
3452     * Certificate used to verify the identity of the server, if it is not set, use system ca.
3453     * @type {?(string | Array<string>)}
3454     * @syscap SystemCapability.Communication.NetStack
3455     * @crossplatform
3456     * @since 12
3457     */
3458    ca?: string | Array<string>;
3459
3460    /**
3461     * Certificate proving the identity of the client
3462     * @type {?string}
3463     * @syscap SystemCapability.Communication.NetStack
3464     * @since 9
3465     */
3466    /**
3467     * Certificate proving the identity of the client
3468     * @type {?string}
3469     * @syscap SystemCapability.Communication.NetStack
3470     * @crossplatform
3471     * @since 10
3472     */
3473    cert?: string;
3474
3475    /**
3476     * Private key of client certificate
3477     * @type {?string}
3478     * @syscap SystemCapability.Communication.NetStack
3479     * @since 9
3480     */
3481    /**
3482     * Private key of client certificate
3483     * @type {?string}
3484     * @syscap SystemCapability.Communication.NetStack
3485     * @crossplatform
3486     * @since 10
3487     */
3488    key?: string;
3489
3490    /**
3491     * Password of the private key
3492     * @type {?string}
3493     * @syscap SystemCapability.Communication.NetStack
3494     * @since 9
3495     */
3496    /**
3497     * Password of the private key
3498     * @type {?string}
3499     * @syscap SystemCapability.Communication.NetStack
3500     * @crossplatform
3501     * @since 10
3502     */
3503    password?: string;
3504
3505    /**
3506     * TLS protocol version
3507     * @type {?Protocol | Array<Protocol>}
3508     * @syscap SystemCapability.Communication.NetStack
3509     * @since 9
3510     */
3511    /**
3512     * TLS protocol version
3513     * @type {?(Protocol | Array<Protocol>)}
3514     * @syscap SystemCapability.Communication.NetStack
3515     * @crossplatform
3516     * @since 10
3517     */
3518    protocols?: Protocol | Array<Protocol>;
3519
3520    /**
3521     * default is false, use local cipher.
3522     * @type {?boolean}
3523     * @syscap SystemCapability.Communication.NetStack
3524     * @since 9
3525     */
3526    /**
3527     * default is false, use local cipher.
3528     * @type {?boolean}
3529     * @syscap SystemCapability.Communication.NetStack
3530     * @crossplatform
3531     * @since 10
3532     */
3533    useRemoteCipherPrefer?: boolean;
3534
3535    /**
3536     * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc),
3537     * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example  rsa_pss_pss_sha512)</P>
3538     * @type {?string}
3539     * @syscap SystemCapability.Communication.NetStack
3540     * @since 9
3541     */
3542    /**
3543     * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc),
3544     * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example  rsa_pss_pss_sha512)</P>
3545     * @type {?string}
3546     * @syscap SystemCapability.Communication.NetStack
3547     * @crossplatform
3548     * @since 10
3549     */
3550    signatureAlgorithms?: string;
3551
3552    /**
3553     * Crypto suite specification
3554     * @type {?string}
3555     * @syscap SystemCapability.Communication.NetStack
3556     * @since 9
3557     */
3558    /**
3559     * Crypto suite specification
3560     * @type {?string}
3561     * @syscap SystemCapability.Communication.NetStack
3562     * @crossplatform
3563     * @since 10
3564     */
3565    cipherSuite?: string;
3566
3567    /**
3568     * Used to set up bidirectional authentication. The default value is false.
3569     * @type {?boolean}
3570     * @syscap SystemCapability.Communication.NetStack
3571     * @since 12
3572     */
3573    isBidirectionalAuthentication?: boolean;
3574  }
3575
3576  /**
3577   * Defines TLS connection options.
3578   * @interface TLSConnectOptions
3579   * @syscap SystemCapability.Communication.NetStack
3580   * @since 9
3581   */
3582  /**
3583   * Defines TLS connection options.
3584   * @interface TLSConnectOptions
3585   * @syscap SystemCapability.Communication.NetStack
3586   * @crossplatform
3587   * @since 10
3588   */
3589  export interface TLSConnectOptions {
3590    /**
3591     * Gateway address.
3592     * @type {NetAddress}
3593     * @syscap SystemCapability.Communication.NetStack
3594     * @since 9
3595     */
3596    /**
3597     * Gateway address.
3598     * @type {NetAddress}
3599     * @syscap SystemCapability.Communication.NetStack
3600     * @crossplatform
3601     * @since 10
3602     */
3603    address: NetAddress;
3604
3605    /**
3606     * Protocol http2TLS security related operations.
3607     * @type {TLSSecureOptions}
3608     * @syscap SystemCapability.Communication.NetStack
3609     * @since 9
3610     */
3611    /**
3612     * Protocol http2TLS security related operations.
3613     * @type {TLSSecureOptions}
3614     * @syscap SystemCapability.Communication.NetStack
3615     * @crossplatform
3616     * @since 10
3617     */
3618    secureOptions: TLSSecureOptions;
3619
3620    /**
3621     * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2"
3622     * @type {?Array<string>}
3623     * @syscap SystemCapability.Communication.NetStack
3624     * @since 9
3625     */
3626    /**
3627     * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2"
3628     * @type {?Array<string>}
3629     * @syscap SystemCapability.Communication.NetStack
3630     * @crossplatform
3631     * @since 10
3632     */
3633    ALPNProtocols?: Array<string>;
3634
3635    /**
3636     * Skip identity verification for remote servers. The default value is false.
3637     * @type {?boolean}
3638     * @syscap SystemCapability.Communication.NetStack
3639     * @since 12
3640     */
3641    skipRemoteValidation?: boolean;
3642  }
3643
3644  /**
3645   * Enumerates TLS protocol versions.
3646   * @enum {string}
3647   * @syscap SystemCapability.Communication.NetStack
3648   * @since 9
3649   */
3650  /**
3651   * Enumerates TLS protocol versions.
3652   * @enum {string}
3653   * @syscap SystemCapability.Communication.NetStack
3654   * @crossplatform
3655   * @since 10
3656   */
3657  export enum Protocol {
3658    /**
3659     * Use TLSv1.2 protocol for communication.
3660     * @syscap SystemCapability.Communication.NetStack
3661     * @since 9
3662     */
3663    /**
3664     * Use TLSv1.2 protocol for communication.
3665     * @syscap SystemCapability.Communication.NetStack
3666     * @crossplatform
3667     * @since 10
3668     */
3669    TLSv12 = "TLSv1.2",
3670
3671    /**
3672     * Use TLSv1.3 protocol for communication.
3673     * @syscap SystemCapability.Communication.NetStack
3674     * @since 9
3675     */
3676    /**
3677     * Use TLSv1.3 protocol for communication.
3678     * @syscap SystemCapability.Communication.NetStack
3679     * @crossplatform
3680     * @since 10
3681     */
3682    TLSv13 = "TLSv1.3"
3683  }
3684
3685  /**
3686   * Defines the connection of the TCPSocket client and server.
3687   * @interface TCPSocketConnection
3688   * @syscap SystemCapability.Communication.NetStack
3689   * @since 10
3690   */
3691  export interface TCPSocketConnection {
3692    /**
3693     * The id of a client connects to the TCPSocketServer.
3694     * @type {number}
3695     * @syscap SystemCapability.Communication.NetStack
3696     * @since 10
3697     */
3698    clientId: number;
3699
3700    /**
3701     * Sends data over a TCPSocketServer connection to client.
3702     * @permission ohos.permission.INTERNET
3703     * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}.
3704     * @param { AsyncCallback<void> } callback - The callback of send.
3705     * @throws { BusinessError } 201 - Permission denied.
3706     * @throws { BusinessError } 401 - Parameter error.
3707     * @throws { BusinessError } 2300002 - System internal error.
3708     * @syscap SystemCapability.Communication.NetStack
3709     * @since 10
3710     */
3711    send(options: TCPSendOptions, callback: AsyncCallback<void>): void;
3712
3713    /**
3714     * Sends data over a TCPSocketServer connection to client.
3715     * @permission ohos.permission.INTERNET
3716     * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}.
3717     * @returns { Promise<void> } The promise returned by the function.
3718     * @throws { BusinessError } 201 - Permission denied.
3719     * @throws { BusinessError } 401 - Parameter error.
3720     * @throws { BusinessError } 2300002 - System internal error.
3721     * @syscap SystemCapability.Communication.NetStack
3722     * @since 10
3723     */
3724    send(options: TCPSendOptions): Promise<void>;
3725
3726    /**
3727     * Closes a TCPSocket client connection.
3728     * @permission ohos.permission.INTERNET
3729     * @param { AsyncCallback<void> } callback - The callback of close.
3730     * @throws { BusinessError } 201 - Permission denied.
3731     * @throws { BusinessError } 401 - Parameter error.
3732     * @throws { BusinessError } 2300002 - System internal error.
3733     * @syscap SystemCapability.Communication.NetStack
3734     * @since 10
3735     */
3736    close(callback: AsyncCallback<void>): void;
3737
3738    /**
3739     * Closes a TCPSocket client connection.
3740     * @permission ohos.permission.INTERNET
3741     * @returns { Promise<void> } The promise returned by the function.
3742     * @throws { BusinessError } 201 - Permission denied.
3743     * @throws { BusinessError } 2300002 - System internal error.
3744     * @syscap SystemCapability.Communication.NetStack
3745     * @since 10
3746     */
3747    close(): Promise<void>;
3748
3749    /**
3750     * Obtains the peer address of a TCPSocketServer connection.
3751     * @permission ohos.permission.INTERNET
3752     * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress.
3753     * @throws { BusinessError } 201 - Permission denied.
3754     * @throws { BusinessError } 401 - Parameter error.
3755     * @throws { BusinessError } 2300002 - System internal error.
3756     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3757     * @syscap SystemCapability.Communication.NetStack
3758     * @since 10
3759     */
3760    getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
3761
3762    /**
3763     * Obtains the peer address of a TCPSocketServer connection.
3764     * @permission ohos.permission.INTERNET
3765     * @returns { Promise<NetAddress> } The promise returned by the function.
3766     * @throws { BusinessError } 201 - Permission denied.
3767     * @throws { BusinessError } 2300002 - System internal error.
3768     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3769     * @syscap SystemCapability.Communication.NetStack
3770     * @since 10
3771     */
3772    getRemoteAddress(): Promise<NetAddress>;
3773
3774    /**
3775     * Obtains the local address of a TCPSocketServer connection.
3776     * @returns { Promise<NetAddress> } The promise returned by the function.
3777     * @throws { BusinessError } 2300002 - System internal error.
3778     * @throws { BusinessError } 2301009 - Bad file descriptor.
3779     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3780     * @syscap SystemCapability.Communication.NetStack
3781     * @since 12
3782     */
3783    getLocalAddress(): Promise<NetAddress>;
3784
3785    /**
3786     * Listens for message receiving events of the TCPSocketConnection.
3787     * @param { 'message' } type - Indicates Event name.
3788     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on.
3789     * @throws { BusinessError } 401 - Parameter error.
3790     * @syscap SystemCapability.Communication.NetStack
3791     * @since 10
3792     */
3793    /**
3794     * Listens for message receiving events of the TCPSocketConnection.
3795     * @param { 'message' } type - Indicates Event name.
3796     * @param { Callback<SocketMessageInfo> } callback - The callback of on.
3797     * @throws { BusinessError } 401 - Parameter error.
3798     * @syscap SystemCapability.Communication.NetStack
3799     * @since 11
3800     */
3801    /**
3802     * Listens for message receiving events of the TCPSocketConnection.
3803     * @param { 'message' } type - Indicates Event name.
3804     * @param { Callback<SocketMessageInfo> } callback - The callback of on.
3805     * @throws { BusinessError } 401 - Parameter error.
3806     * @syscap SystemCapability.Communication.NetStack
3807     * @crossplatform
3808     * @since 12
3809     */
3810    on(type: 'message', callback: Callback<SocketMessageInfo>): void;
3811
3812    /**
3813     * Cancels listening for message receiving events of the TCPSocketConnection.
3814     * @param { 'message' } type - Indicates Event name.
3815     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off.
3816     * @throws { BusinessError } 401 - Parameter error.
3817     * @syscap SystemCapability.Communication.NetStack
3818     * @since 10
3819     */
3820    /**
3821     * Cancels listening for message receiving events of the TCPSocketConnection.
3822     * @param { 'message' } type - Indicates Event name.
3823     * @param { Callback<SocketMessageInfo> } callback - The callback of off.
3824     * @throws { BusinessError } 401 - Parameter error.
3825     * @syscap SystemCapability.Communication.NetStack
3826     * @since 11
3827     */
3828    /**
3829     * Cancels listening for message receiving events of the TCPSocketConnection.
3830     * @param { 'message' } type - Indicates Event name.
3831     * @param { Callback<SocketMessageInfo> } callback - The callback of off.
3832     * @throws { BusinessError } 401 - Parameter error.
3833     * @syscap SystemCapability.Communication.NetStack
3834     * @crossplatform
3835     * @since 12
3836     */
3837    off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
3838
3839    /**
3840     * Listens for close events of the TCPSocketConnection.
3841     * @param { 'close' } type - Indicates Event name.
3842     * @param { Callback<void> } callback - The callback of on.
3843     * @throws { BusinessError } 401 - Parameter error.
3844     * @syscap SystemCapability.Communication.NetStack
3845     * @since 10
3846     */
3847    on(type: 'close', callback: Callback<void>): void;
3848
3849    /**
3850     * Cancels listening for close events of the TCPSocketConnection.
3851     * @param { 'close' } type - Indicates Event name.
3852     * @param { Callback<void> } callback - The callback of off.
3853     * @throws { BusinessError } 401 - Parameter error.
3854     * @syscap SystemCapability.Communication.NetStack
3855     * @since 10
3856     */
3857    off(type: 'close', callback?: Callback<void>): void;
3858
3859    /**
3860     * Listens for error events of the TCPSocketConnection.
3861     * @param { 'error' } type - Indicates Event name.
3862     * @param { ErrorCallback } callback - The callback of on.
3863     * @throws { BusinessError } 401 - Parameter error.
3864     * @syscap SystemCapability.Communication.NetStack
3865     * @since 10
3866     */
3867    on(type: 'error', callback: ErrorCallback): void;
3868
3869    /**
3870     * Cancels listening for error events of the TCPSocketConnection.
3871     * @param { 'error' } type - Indicates Event name.
3872     * @param { ErrorCallback } callback - The callback of off.
3873     * @throws { BusinessError } 401 - Parameter error.
3874     * @syscap SystemCapability.Communication.NetStack
3875     * @since 10
3876     */
3877    off(type: 'error', callback?: ErrorCallback): void;
3878  }
3879
3880  /**
3881   * Defines a TCPSocket server connection.
3882   * @interface TCPSocketServer
3883   * @syscap SystemCapability.Communication.NetStack
3884   * @since 10
3885   */
3886  export interface TCPSocketServer {
3887    /**
3888     * Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
3889     * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
3890     * for accept processing and uses poll multiplex to process client connections.</p>
3891     * @permission ohos.permission.INTERNET
3892     * @param { NetAddress } address - Network address information {@link NetAddress}.
3893     * @param { AsyncCallback<void> } callback - The callback of listen.
3894     * @throws { BusinessError } 401 - Parameter error.
3895     * @throws { BusinessError } 201 - Permission denied.
3896     * @throws { BusinessError } 2300002 - System internal error.
3897     * @throws { BusinessError } 2303109 - Bad file number.
3898     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3899     * @throws { BusinessError } 2303198 - Address already in use.
3900     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3901     * @syscap SystemCapability.Communication.NetStack
3902     * @since 10
3903     */
3904    listen(address: NetAddress, callback: AsyncCallback<void>): void;
3905
3906    /**
3907     * Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
3908     * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
3909     * for accept processing and uses poll multiplex to process client connections.</p>
3910     * @permission ohos.permission.INTERNET
3911     * @param { NetAddress } address - Network address information {@link NetAddress}.
3912     * @returns { Promise<void> } The promise returned by the function.
3913     * @throws { BusinessError } 401 - Parameter error.
3914     * @throws { BusinessError } 201 - Permission denied.
3915     * @throws { BusinessError } 2300002 - System internal error.
3916     * @throws { BusinessError } 2303109 - Bad file number.
3917     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
3918     * @throws { BusinessError } 2303198 - Address already in use.
3919     * @throws { BusinessError } 2303199 - Cannot assign requested address.
3920     * @syscap SystemCapability.Communication.NetStack
3921     * @since 10
3922     */
3923    listen(address: NetAddress): Promise<void>;
3924
3925    /**
3926     * Obtains the status of the TCPSocketServer connection.
3927     * @permission ohos.permission.INTERNET
3928     * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState.
3929     * @throws { BusinessError } 201 - Permission denied.
3930     * @throws { BusinessError } 401 - Parameter error.
3931     * @throws { BusinessError } 2300002 - System internal error.
3932     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3933     * @syscap SystemCapability.Communication.NetStack
3934     * @since 10
3935     */
3936    getState(callback: AsyncCallback<SocketStateBase>): void;
3937
3938    /**
3939     * Obtains the status of the TCPSocketServer connection.
3940     * @permission ohos.permission.INTERNET
3941     * @returns { Promise<SocketStateBase> } The promise returned by the function.
3942     * @throws { BusinessError } 201 - Permission denied.
3943     * @throws { BusinessError } 2300002 - System internal error.
3944     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3945     * @syscap SystemCapability.Communication.NetStack
3946     * @since 10
3947     */
3948    getState(): Promise<SocketStateBase>;
3949
3950    /**
3951     * Sets other attributes of the TCPSocketServer connection.
3952     * @permission ohos.permission.INTERNET
3953     * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
3954     * @param { AsyncCallback<void> } callback - The callback of setExtraOptions.
3955     * @throws { BusinessError } 201 - Permission denied.
3956     * @throws { BusinessError } 401 - Parameter error.
3957     * @throws { BusinessError } 2300002 - System internal error.
3958     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3959     * @syscap SystemCapability.Communication.NetStack
3960     * @since 10
3961     */
3962    setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
3963
3964    /**
3965     * Sets other attributes of the TCPSocketServer connection.
3966     * @permission ohos.permission.INTERNET
3967     * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
3968     * @returns { Promise<void> } The promise returned by the function.
3969     * @throws { BusinessError } 201 - Permission denied.
3970     * @throws { BusinessError } 401 - Parameter error.
3971     * @throws { BusinessError } 2300002 - System internal error.
3972     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3973     * @syscap SystemCapability.Communication.NetStack
3974     * @since 10
3975     */
3976    setExtraOptions(options: TCPExtraOptions): Promise<void>;
3977
3978    /**
3979     * Obtains the local address of a TCPSocketServer connection.
3980     * @returns { Promise<NetAddress> } The promise returned by the function.
3981     * @throws { BusinessError } 2300002 - System internal error.
3982     * @throws { BusinessError } 2301009 - Bad file descriptor.
3983     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
3984     * @syscap SystemCapability.Communication.NetStack
3985     * @since 12
3986     */
3987    getLocalAddress(): Promise<NetAddress>;
3988
3989    /**
3990     * Listens for connect events of the TCPSocketServer connection.
3991     * @param { 'connect' } type - Indicates Event name.
3992     * @param { Callback<TCPSocketConnection> } callback - The callback of on.
3993     * @throws { BusinessError } 401 - Parameter error.
3994     * @syscap SystemCapability.Communication.NetStack
3995     * @since 10
3996     */
3997    on(type: 'connect', callback: Callback<TCPSocketConnection>): void;
3998
3999    /**
4000     * Cancels listening for connect events of the TCPSocketServer connection.
4001     * @param { 'connect' } type - Indicates Event name.
4002     * @param { Callback<TCPSocketConnection> } callback - The callback of off.
4003     * @throws { BusinessError } 401 - Parameter error.
4004     * @syscap SystemCapability.Communication.NetStack
4005     * @since 10
4006     */
4007    off(type: 'connect', callback?: Callback<TCPSocketConnection>): void;
4008
4009    /**
4010     * Listens for error events of the TCPSocketServer connection.
4011     * @param { 'error' } type - Indicates Event name.
4012     * @param { ErrorCallback } callback - The callback of on.
4013     * @throws { BusinessError } 401 - Parameter error.
4014     * @syscap SystemCapability.Communication.NetStack
4015     * @since 10
4016     */
4017    on(type: 'error', callback: ErrorCallback): void;
4018
4019    /**
4020     * Cancels listening for error events of the TCPSocketServer connection.
4021     * @param { 'error' } type - Indicates Event name.
4022     * @param { ErrorCallback } callback - The callback of off.
4023     * @throws { BusinessError } 401 - Parameter error.
4024     * @syscap SystemCapability.Communication.NetStack
4025     * @since 10
4026     */
4027    off(type: 'error', callback?: ErrorCallback): void;
4028  }
4029
4030  /**
4031   * Defines the connection of the TLSSocket client and server.
4032   * @interface TLSSocketConnection
4033   * @syscap SystemCapability.Communication.NetStack
4034   * @since 10
4035   */
4036  export interface TLSSocketConnection {
4037    /**
4038     * The id of a client connects to the TLSSocketServer.
4039     * @type {number}
4040     * @syscap SystemCapability.Communication.NetStack
4041     * @since 10
4042     */
4043    clientId: number;
4044
4045    /**
4046     * Sends data over a TLSSocketServer connection to client.
4047     * @param { string } data - Parameters for sending data.
4048     * @param { AsyncCallback<void> } callback - The callback of send.
4049     * @throws { BusinessError } 401 - Parameter error.
4050     * @throws { BusinessError } 2303501 - SSL is null.
4051     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4052     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4053     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4054     * @throws { BusinessError } 2300002 - System internal error.
4055     * @syscap SystemCapability.Communication.NetStack
4056     * @since 10
4057     */
4058    /**
4059     * Sends data over a TLSSocketServer connection to client.
4060     * @param { string | ArrayBuffer } data - Parameters for sending data.
4061     * @param { AsyncCallback<void> } callback - The callback of send.
4062     * @throws { BusinessError } 401 - Parameter error.
4063     * @throws { BusinessError } 2303501 - SSL is null.
4064     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4065     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4066     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4067     * @throws { BusinessError } 2300002 - System internal error.
4068     * @syscap SystemCapability.Communication.NetStack
4069     * @since 12
4070     */
4071    send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void;
4072
4073    /**
4074     * Sends data over a TLSSocketServer connection to client.
4075     * @param { string } data - Parameters for sending data.
4076     * @returns { Promise<void> } The promise returned by the function.
4077     * @throws { BusinessError } 401 - Parameter error.
4078     * @throws { BusinessError } 2303501 - SSL is null.
4079     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4080     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4081     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4082     * @throws { BusinessError } 2300002 - System internal error.
4083     * @syscap SystemCapability.Communication.NetStack
4084     * @since 10
4085     */
4086    /**
4087     * Sends data over a TLSSocketServer connection to client.
4088     * @param { string | ArrayBuffer } data - Parameters for sending data.
4089     * @returns { Promise<void> } The promise returned by the function.
4090     * @throws { BusinessError } 401 - Parameter error.
4091     * @throws { BusinessError } 2303501 - SSL is null.
4092     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4093     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4094     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4095     * @throws { BusinessError } 2300002 - System internal error.
4096     * @syscap SystemCapability.Communication.NetStack
4097     * @since 12
4098     */
4099    send(data: string | ArrayBuffer): Promise<void>;
4100
4101    /**
4102     * Closes a TLSSocket client connection.
4103     * @param { AsyncCallback<void> } callback - The callback of close.
4104     * @throws { BusinessError } 401 - Parameter error.
4105     * @throws { BusinessError } 2303501 - SSL is null.
4106     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4107     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4108     * @throws { BusinessError } 2300002 - System internal error.
4109     * @syscap SystemCapability.Communication.NetStack
4110     * @since 10
4111     */
4112    close(callback: AsyncCallback<void>): void;
4113
4114    /**
4115     * Closes a TLSSocket client connection.
4116     * @returns { Promise<void> } The promise returned by the function.
4117     * @throws { BusinessError } 2303501 - SSL is null.
4118     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4119     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4120     * @throws { BusinessError } 2300002 - System internal error.
4121     * @syscap SystemCapability.Communication.NetStack
4122     * @since 10
4123     */
4124    close(): Promise<void>;
4125
4126    /**
4127     * Obtains the peer address of a TLSSocketServer connection.
4128     * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress.
4129     * @throws { BusinessError } 401 - Parameter error.
4130     * @throws { BusinessError } 2300002 - System internal error.
4131     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4132     * @syscap SystemCapability.Communication.NetStack
4133     * @since 10
4134     */
4135    getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
4136
4137    /**
4138     * Obtains the peer address of a TLSSocketServer connection.
4139     * @returns { Promise<NetAddress> } The promise returned by the function.
4140     * @throws { BusinessError } 2300002 - System internal error.
4141     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4142     * @syscap SystemCapability.Communication.NetStack
4143     * @since 10
4144     */
4145    getRemoteAddress(): Promise<NetAddress>;
4146
4147    /**
4148     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
4149     * an empty object will be returned. If the socket is destroyed, null is returned.</p>
4150     * It only contains the peer's certificate.
4151     * @param { AsyncCallback<X509CertRawData> } callback - The callback of getRemoteCertificate.
4152     * @throws { BusinessError } 401 - Parameter error.
4153     * @throws { BusinessError } 2303501 - SSL is null.
4154     * @throws { BusinessError } 2300002 - System internal error.
4155     * @syscap SystemCapability.Communication.NetStack
4156     * @since 10
4157     */
4158    getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void;
4159
4160    /**
4161     * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
4162     * an empty object will be returned. If the socket is destroyed, null is returned.</p>
4163     * It only contains the peer's certificate.
4164     * @returns { Promise<X509CertRawData> } The promise returned by the function.
4165     * @throws { BusinessError } 2303501 - SSL is null.
4166     * @throws { BusinessError } 2300002 - System internal error.
4167     * @syscap SystemCapability.Communication.NetStack
4168     * @since 10
4169     */
4170    getRemoteCertificate(): Promise<X509CertRawData>;
4171
4172    /**
4173     * Returns a list containing the negotiated cipher suite information.
4174     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
4175     * @param { AsyncCallback<Array<string>> } callback - The callback of getCipherSuite.
4176     * @throws { BusinessError } 401 - Parameter error.
4177     * @throws { BusinessError } 2303501 - SSL is null.
4178     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
4179     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4180     * @throws { BusinessError } 2300002 - System internal error.
4181     * @syscap SystemCapability.Communication.NetStack
4182     * @since 10
4183     */
4184    getCipherSuite(callback: AsyncCallback<Array<string>>): void;
4185
4186    /**
4187     * Returns a list containing the negotiated cipher suite information.
4188     * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
4189     * @returns { Promise<Array<string>> } The promise returned by the function.
4190     * @throws { BusinessError } 2303501 - SSL is null.
4191     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
4192     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4193     * @throws { BusinessError } 2300002 - System internal error.
4194     * @syscap SystemCapability.Communication.NetStack
4195     * @since 10
4196     */
4197    getCipherSuite(): Promise<Array<string>>;
4198
4199    /**
4200     * <p>The list of signature algorithms shared between the server and the client,
4201     * in descending order of priority.</p>
4202     * @param { AsyncCallback<Array<string>> } callback - The callback of getSignatureAlgorithms.
4203     * @throws { BusinessError } 401 - Parameter error.
4204     * @throws { BusinessError } 2303501 - SSL is null.
4205     * @throws { BusinessError } 2300002 - System internal error.
4206     * @syscap SystemCapability.Communication.NetStack
4207     * @since 10
4208     */
4209    getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void;
4210
4211    /**
4212     * <p>The list of signature algorithms shared between the server and the client,
4213     * in descending order of priority.</p>
4214     * @returns { Promise<Array<string>> } The promise returned by the function.
4215     * @throws { BusinessError } 2303501 - SSL is null.
4216     * @throws { BusinessError } 2300002 - System internal error.
4217     * @syscap SystemCapability.Communication.NetStack
4218     * @since 10
4219     */
4220    getSignatureAlgorithms(): Promise<Array<string>>;
4221
4222    /**
4223     * Obtains the local address of a TLSSocketServer connection.
4224     * @returns { Promise<NetAddress> } The promise returned by the function.
4225     * @throws { BusinessError } 2300002 - System internal error.
4226     * @throws { BusinessError } 2301009 - Bad file descriptor.
4227     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4228     * @syscap SystemCapability.Communication.NetStack
4229     * @since 12
4230     */
4231    getLocalAddress(): Promise<NetAddress>;
4232
4233    /**
4234     * Listens for message receiving events of the TLSSocketConnection.
4235     * @param { 'message' } type - Indicates Event name.
4236     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on.
4237     * @throws { BusinessError } 401 - Parameter error.
4238     * @syscap SystemCapability.Communication.NetStack
4239     * @since 10
4240     */
4241    /**
4242     * Listens for message receiving events of the TLSSocketConnection.
4243     * @param { 'message' } type - Indicates Event name.
4244     * @param { Callback<SocketMessageInfo> } callback - The callback of on.
4245     * @throws { BusinessError } 401 - Parameter error.
4246     * @syscap SystemCapability.Communication.NetStack
4247     * @since 11
4248     */
4249    /**
4250     * Listens for message receiving events of the TLSSocketConnection.
4251     * @param { 'message' } type - Indicates Event name.
4252     * @param { Callback<SocketMessageInfo> } callback - The callback of on.
4253     * @throws { BusinessError } 401 - Parameter error.
4254     * @syscap SystemCapability.Communication.NetStack
4255     * @crossplatform
4256     * @since 12
4257     */
4258    on(type: 'message', callback: Callback<SocketMessageInfo>): void;
4259
4260    /**
4261     * Cancels listening for message receiving events of the TLSSocketConnection.
4262     * @param { 'message' } type - Indicates Event name.
4263     * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off.
4264     * @throws { BusinessError } 401 - Parameter error.
4265     * @syscap SystemCapability.Communication.NetStack
4266     * @since 10
4267     */
4268    /**
4269     * Cancels listening for message receiving events of the TLSSocketConnection.
4270     * @param { 'message' } type - Indicates Event name.
4271     * @param { Callback<SocketMessageInfo> } callback - The callback of off.
4272     * @throws { BusinessError } 401 - Parameter error.
4273     * @syscap SystemCapability.Communication.NetStack
4274     * @since 11
4275     */
4276    /**
4277     * Cancels listening for message receiving events of the TLSSocketConnection.
4278     * @param { 'message' } type - Indicates Event name.
4279     * @param { Callback<SocketMessageInfo> } callback - The callback of off.
4280     * @throws { BusinessError } 401 - Parameter error.
4281     * @syscap SystemCapability.Communication.NetStack
4282     * @crossplatform
4283     * @since 12
4284     */
4285    off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
4286
4287    /**
4288     * Listens for close events of the TLSSocketConnection.
4289     * @param { 'close' } type - Indicates Event name.
4290     * @param { Callback<void> } callback - The callback of on.
4291     * @throws { BusinessError } 401 - Parameter error.
4292     * @syscap SystemCapability.Communication.NetStack
4293     * @since 10
4294     */
4295    on(type: 'close', callback: Callback<void>): void;
4296
4297    /**
4298     * Cancels listening for close events of the TLSSocketConnection.
4299     * @param { 'close' } type - Indicates Event name.
4300     * @param { Callback<void> } callback - The callback of off.
4301     * @throws { BusinessError } 401 - Parameter error.
4302     * @syscap SystemCapability.Communication.NetStack
4303     * @since 10
4304     */
4305    off(type: 'close', callback?: Callback<void>): void;
4306
4307    /**
4308     * Listens for error events of the TLSSocketConnection.
4309     * @param { 'error' } type - Indicates Event name.
4310     * @param { ErrorCallback } callback - The callback of on.
4311     * @throws { BusinessError } 401 - Parameter error.
4312     * @syscap SystemCapability.Communication.NetStack
4313     * @since 10
4314     */
4315    on(type: 'error', callback: ErrorCallback): void;
4316
4317    /**
4318     * Cancels listening for error events of the TLSSocketConnection.
4319     * @param { 'error' } type - Indicates Event name.
4320     * @param { ErrorCallback } callback - The callback of off.
4321     * @throws { BusinessError } 401 - Parameter error.
4322     * @syscap SystemCapability.Communication.NetStack
4323     * @since 10
4324     */
4325    off(type: 'error', callback?: ErrorCallback): void;
4326  }
4327
4328  /**
4329   * Defines the socket connection information.
4330   * @interface SocketMessageInfo
4331   * @syscap SystemCapability.Communication.NetStack
4332   * @crossplatform
4333   * @since 11
4334   */
4335  export interface SocketMessageInfo {
4336    /**
4337     * Receive the message event.
4338     * @type { ArrayBuffer }
4339     * @syscap SystemCapability.Communication.NetStack
4340     * @crossplatform
4341     * @since 11
4342     */
4343    message: ArrayBuffer;
4344    /**
4345     * Socket connection information.
4346     * @type { SocketRemoteInfo }
4347     * @syscap SystemCapability.Communication.NetStack
4348     * @crossplatform
4349     * @since 11
4350     */
4351    remoteInfo: SocketRemoteInfo;
4352  }
4353
4354  /**
4355   * Defines a TLSSocketServer server connection.
4356   * @interface TLSSocketServer
4357   * @syscap SystemCapability.Communication.NetStack
4358   * @since 10
4359   */
4360  export interface TLSSocketServer {
4361    /**
4362     * Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
4363     * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
4364     * for accept processing and uses poll multiplex to process client connections.</p>
4365     * @permission ohos.permission.INTERNET
4366     * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}.
4367     * @param { AsyncCallback<void> } callback - The callback of listen.
4368     * @throws { BusinessError } 401 - Parameter error.
4369     * @throws { BusinessError } 201 - Permission denied.
4370     * @throws { BusinessError } 2300002 - System internal error.
4371     * @throws { BusinessError } 2303109 - Bad file number.
4372     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
4373     * @throws { BusinessError } 2303198 - Address already in use.
4374     * @throws { BusinessError } 2303199 - Cannot assign requested address.
4375     * @throws { BusinessError } 2303501 - SSL is null.
4376     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
4377     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4378     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4379     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4380     * @syscap SystemCapability.Communication.NetStack
4381     * @since 10
4382     */
4383    listen(options: TLSConnectOptions, callback: AsyncCallback<void>): void;
4384
4385    /**
4386     * Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
4387     * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
4388     * for accept processing and uses poll multiplex to process client connections.</p>
4389     * @permission ohos.permission.INTERNET
4390     * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}.
4391     * @returns { Promise<void> } The promise returned by the function.
4392     * @throws { BusinessError } 401 - Parameter error.
4393     * @throws { BusinessError } 201 - Permission denied.
4394     * @throws { BusinessError } 2300002 - System internal error.
4395     * @throws { BusinessError } 2303109 - Bad file number.
4396     * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
4397     * @throws { BusinessError } 2303198 - Address already in use.
4398     * @throws { BusinessError } 2303199 - Cannot assign requested address.
4399     * @throws { BusinessError } 2303501 - SSL is null.
4400     * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
4401     * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
4402     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4403     * @throws { BusinessError } 2303506 - Failed to close the TLS connection.
4404     * @syscap SystemCapability.Communication.NetStack
4405     * @since 10
4406     */
4407    listen(options: TLSConnectOptions): Promise<void>;
4408
4409    /**
4410     * Obtains the status of the TLSSocketServer connection.
4411     * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState.
4412     * @throws { BusinessError } 401 - Parameter error.
4413     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4414     * @throws { BusinessError } 2300002 - System internal error.
4415     * @syscap SystemCapability.Communication.NetStack
4416     * @since 10
4417     */
4418    getState(callback: AsyncCallback<SocketStateBase>): void;
4419
4420    /**
4421     * Obtains the status of the TLSSocketServer connection.
4422     * @returns { Promise<SocketStateBase> } The promise returned by the function.
4423     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4424     * @throws { BusinessError } 2300002 - System internal error.
4425     * @syscap SystemCapability.Communication.NetStack
4426     * @since 10
4427     */
4428    getState(): Promise<SocketStateBase>;
4429
4430    /**
4431     * Sets other attributes of the TLSSocketServer connection.
4432     * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
4433     * @param { AsyncCallback<void> } callback - The callback of setExtraOptions.
4434     * @throws { BusinessError } 401 - Parameter error.
4435     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4436     * @throws { BusinessError } 2300002 - System internal error.
4437     * @syscap SystemCapability.Communication.NetStack
4438     * @since 10
4439     */
4440    setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
4441
4442    /**
4443     * Sets other attributes of the TLSSocketServer connection.
4444     * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
4445     * @returns { Promise<void> } The promise returned by the function.
4446     * @throws { BusinessError } 401 - Parameter error.
4447     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4448     * @throws { BusinessError } 2300002 - System internal error.
4449     * @syscap SystemCapability.Communication.NetStack
4450     * @since 10
4451     */
4452    setExtraOptions(options: TCPExtraOptions): Promise<void>;
4453
4454    /**
4455     * Returns an object representing a local certificate.
4456     * @param { AsyncCallback<X509CertRawData> } callback - The callback of getCertificate.
4457     * @throws { BusinessError } 401 - Parameter error.
4458     * @throws { BusinessError } 2303501 - SSL is null.
4459     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
4460     * @throws { BusinessError } 2300002 - System internal error.
4461     * @syscap SystemCapability.Communication.NetStack
4462     * @since 10
4463     */
4464    getCertificate(callback: AsyncCallback<X509CertRawData>): void;
4465
4466    /**
4467     * Returns an object representing a local certificate.
4468     * @returns { Promise<X509CertRawData> } The promise returned by the function.
4469     * @throws { BusinessError } 2303501 - SSL is null.
4470     * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
4471     * @throws { BusinessError } 2300002 - System internal error.
4472     * @syscap SystemCapability.Communication.NetStack
4473     * @since 10
4474     */
4475    getCertificate(): Promise<X509CertRawData>;
4476
4477    /**
4478     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
4479     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
4480     * Server sockets or disconnected client sockets will return a value of null.
4481     * @param { AsyncCallback<string> } callback - The callback of getProtocol.
4482     * @throws { BusinessError } 401 - Parameter error.
4483     * @throws { BusinessError } 2303501 - SSL is null.
4484     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4485     * @throws { BusinessError } 2300002 - System internal error.
4486     * @syscap SystemCapability.Communication.NetStack
4487     * @since 10
4488     */
4489    getProtocol(callback: AsyncCallback<string>): void;
4490
4491    /**
4492     * Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
4493     * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
4494     * Server sockets or disconnected client sockets will return a value of null.
4495     * @returns { Promise<string> } The promise returned by the function.
4496     * @throws { BusinessError } 2303501 - SSL is null.
4497     * @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
4498     * @throws { BusinessError } 2300002 - System internal error.
4499     * @syscap SystemCapability.Communication.NetStack
4500     * @since 10
4501     */
4502    getProtocol(): Promise<string>;
4503
4504    /**
4505     * Obtains the local address of the TLSSocketServer connection.
4506     * @returns { Promise<NetAddress> } The promise returned by the function.
4507     * @throws { BusinessError } 2300002 - System internal error.
4508     * @throws { BusinessError } 2301009 - Bad file descriptor.
4509     * @throws { BusinessError } 2303188 - Socket operation on non-socket.
4510     * @syscap SystemCapability.Communication.NetStack
4511     * @since 12
4512     */
4513    getLocalAddress(): Promise<NetAddress>;
4514
4515    /**
4516     * Listens for connect events of the TLSSocketServer connection.
4517     * @param { 'connect' } type - Indicates Event name.
4518     * @param { Callback<TLSSocketConnection> } callback - The callback of on.
4519     * @throws { BusinessError } 401 - Parameter error.
4520     * @syscap SystemCapability.Communication.NetStack
4521     * @since 10
4522     */
4523    on(type: 'connect', callback: Callback<TLSSocketConnection>): void;
4524
4525    /**
4526     * Cancels listening for connect events of the TLSSocketServer connection.
4527     * @param { 'connect' } type - Indicates Event name.
4528     * @param { Callback<TLSSocketConnection> } callback - The callback of off.
4529     * @throws { BusinessError } 401 - Parameter error.
4530     * @syscap SystemCapability.Communication.NetStack
4531     * @since 10
4532     */
4533    off(type: 'connect', callback?: Callback<TLSSocketConnection>): void;
4534
4535    /**
4536     * Listens for error events of the TLSSocketServer connection.
4537     * @param { 'error' } type - Indicates Event name.
4538     * @param { ErrorCallback } callback - The callback of on.
4539     * @throws { BusinessError } 401 - Parameter error.
4540     * @syscap SystemCapability.Communication.NetStack
4541     * @since 10
4542     */
4543    on(type: 'error', callback: ErrorCallback): void;
4544
4545    /**
4546     * Cancels listening for error events of the TLSSocketServer connection.
4547     * @param { 'error' } type - Indicates Event name.
4548     * @param { ErrorCallback } callback - The callback of off.
4549     * @throws { BusinessError } 401 - Parameter error.
4550     * @syscap SystemCapability.Communication.NetStack
4551     * @since 10
4552     */
4553    off(type: 'error', callback?: ErrorCallback): void;
4554  }
4555}
4556
4557export default socket;
4558