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