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