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 * Listens for connect events of the LocalSocketServer connection. 2042 * @param { 'connect' } type - Indicates Event name. 2043 * @param { Callback<LocalSocketConnection> } callback - The callback of on. 2044 * @throws { BusinessError } 401 - Parameter error. 2045 * @syscap SystemCapability.Communication.NetStack 2046 * @since 11 2047 */ 2048 /** 2049 * Listens for connect events of the LocalSocketServer connection. 2050 * @param { 'connect' } type - Indicates Event name. 2051 * @param { Callback<LocalSocketConnection> } callback - The callback of on. 2052 * @throws { BusinessError } 401 - Parameter error. 2053 * @syscap SystemCapability.Communication.NetStack 2054 * @crossplatform 2055 * @since 12 2056 */ 2057 on(type: 'connect', callback: Callback<LocalSocketConnection>): void; 2058 2059 /** 2060 * Cancels listening for connect events of the LocalSocketServer connection. 2061 * @param { 'connect' } type - Indicates Event name. 2062 * @param { Callback<LocalSocketConnection> } callback - The callback of off. 2063 * @throws { BusinessError } 401 - Parameter error. 2064 * @syscap SystemCapability.Communication.NetStack 2065 * @since 11 2066 */ 2067 /** 2068 * Cancels listening for connect events of the LocalSocketServer connection. 2069 * @param { 'connect' } type - Indicates Event name. 2070 * @param { Callback<LocalSocketConnection> } callback - The callback of off. 2071 * @throws { BusinessError } 401 - Parameter error. 2072 * @syscap SystemCapability.Communication.NetStack 2073 * @crossplatform 2074 * @since 12 2075 */ 2076 off(type: 'connect', callback?: Callback<LocalSocketConnection>): void; 2077 2078 /** 2079 * Listens for error events of the LocalSocketServer connection. 2080 * @param { 'error' } type - Indicates Event name. 2081 * @param { ErrorCallback } callback - The callback of on. 2082 * @throws { BusinessError } 401 - Parameter error. 2083 * @syscap SystemCapability.Communication.NetStack 2084 * @since 11 2085 */ 2086 /** 2087 * Listens for error events of the LocalSocketServer connection. 2088 * @param { 'error' } type - Indicates Event name. 2089 * @param { ErrorCallback } callback - The callback of on. 2090 * @throws { BusinessError } 401 - Parameter error. 2091 * @syscap SystemCapability.Communication.NetStack 2092 * @crossplatform 2093 * @since 12 2094 */ 2095 on(type: 'error', callback: ErrorCallback): void; 2096 2097 /** 2098 * Cancels listening for error events of the LocalSocketServer connection. 2099 * @param { 'error' } type - Indicates Event name. 2100 * @param { ErrorCallback } callback - The callback of off. 2101 * @throws { BusinessError } 401 - Parameter error. 2102 * @syscap SystemCapability.Communication.NetStack 2103 * @since 11 2104 */ 2105 /** 2106 * Cancels listening for error events of the LocalSocketServer connection. 2107 * @param { 'error' } type - Indicates Event name. 2108 * @param { ErrorCallback } callback - The callback of off. 2109 * @throws { BusinessError } 401 - Parameter error. 2110 * @syscap SystemCapability.Communication.NetStack 2111 * @crossplatform 2112 * @since 12 2113 */ 2114 off(type: 'error', callback?: ErrorCallback): void; 2115 } 2116 2117 /** 2118 * Defines TCPSocket connection parameters. 2119 * @interface TCPConnectOptions 2120 * @syscap SystemCapability.Communication.NetStack 2121 * @since 7 2122 */ 2123 /** 2124 * Defines TCPSocket connection parameters. 2125 * @interface TCPConnectOptions 2126 * @syscap SystemCapability.Communication.NetStack 2127 * @crossplatform 2128 * @since 10 2129 */ 2130 export interface TCPConnectOptions { 2131 /** 2132 * Bound IP address and port number. 2133 * @type { NetAddress } 2134 * @syscap SystemCapability.Communication.NetStack 2135 * @since 7 2136 */ 2137 /** 2138 * Bound IP address and port number. 2139 * @type { NetAddress } 2140 * @syscap SystemCapability.Communication.NetStack 2141 * @crossplatform 2142 * @since 10 2143 */ 2144 address: NetAddress; 2145 2146 /** 2147 * Timeout duration of the TCPSocket connection, in milliseconds. 2148 * @type { ?number } 2149 * @syscap SystemCapability.Communication.NetStack 2150 * @since 7 2151 */ 2152 /** 2153 * Timeout duration of the TCPSocket connection, in milliseconds. 2154 * @type { ?number } 2155 * @syscap SystemCapability.Communication.NetStack 2156 * @crossplatform 2157 * @since 10 2158 */ 2159 timeout?: number; 2160 2161 /** 2162 * Set this option for the proxy feature. 2163 * @type {?ProxyOptions} 2164 * @syscap SystemCapability.Communication.NetStack 2165 * @crossplatform 2166 * @since 18 2167 */ 2168 proxy?: ProxyOptions; 2169 } 2170 2171 /** 2172 * Defines the parameters for sending data over the TCPSocket connection. 2173 * @interface TCPSendOptions 2174 * @syscap SystemCapability.Communication.NetStack 2175 * @since 7 2176 */ 2177 /** 2178 * Defines the parameters for sending data over the TCPSocket connection. 2179 * @interface TCPSendOptions 2180 * @syscap SystemCapability.Communication.NetStack 2181 * @crossplatform 2182 * @since 10 2183 */ 2184 export interface TCPSendOptions { 2185 /** 2186 * Data to send. 2187 * @type { string | ArrayBuffer } 2188 * @syscap SystemCapability.Communication.NetStack 2189 * @since 7 2190 */ 2191 /** 2192 * Data to send. 2193 * @type { string | ArrayBuffer } 2194 * @syscap SystemCapability.Communication.NetStack 2195 * @crossplatform 2196 * @since 10 2197 */ 2198 data: string | ArrayBuffer; 2199 2200 /** 2201 * Character encoding format. 2202 * @type { ?string } 2203 * @syscap SystemCapability.Communication.NetStack 2204 * @since 7 2205 */ 2206 /** 2207 * Character encoding format. 2208 * @type { ?string } 2209 * @syscap SystemCapability.Communication.NetStack 2210 * @crossplatform 2211 * @since 10 2212 */ 2213 encoding?: string; 2214 } 2215 2216 /** 2217 * Defines other properties of the TCPSocket connection. 2218 * @interface TCPExtraOptions 2219 * @syscap SystemCapability.Communication.NetStack 2220 * @since 7 2221 */ 2222 /** 2223 * Defines other properties of the TCPSocket connection. 2224 * @extends ExtraOptionsBase 2225 * @interface TCPExtraOptions 2226 * @syscap SystemCapability.Communication.NetStack 2227 * @crossplatform 2228 * @since 10 2229 */ 2230 export interface TCPExtraOptions extends ExtraOptionsBase { 2231 /** 2232 * Whether to keep the connection alive. The default value is false. 2233 * @type { ?boolean } 2234 * @syscap SystemCapability.Communication.NetStack 2235 * @since 7 2236 */ 2237 /** 2238 * Whether to keep the connection alive. The default value is false. 2239 * @type { ?boolean } 2240 * @syscap SystemCapability.Communication.NetStack 2241 * @crossplatform 2242 * @since 10 2243 */ 2244 keepAlive?: boolean; 2245 2246 /** 2247 * Whether to enable OOBInline. The default value is false. 2248 * @type { ?boolean } 2249 * @syscap SystemCapability.Communication.NetStack 2250 * @since 7 2251 */ 2252 /** 2253 * Whether to enable OOBInline. The default value is false. 2254 * @type { ?boolean } 2255 * @syscap SystemCapability.Communication.NetStack 2256 * @crossplatform 2257 * @since 10 2258 */ 2259 OOBInline?: boolean; 2260 2261 /** 2262 * Whether to enable no-delay on the TCPSocket connection. The default value is false. 2263 * @type { ?boolean } 2264 * @syscap SystemCapability.Communication.NetStack 2265 * @since 7 2266 */ 2267 /** 2268 * Whether to enable no-delay on the TCPSocket connection. The default value is false. 2269 * @type { ?boolean } 2270 * @syscap SystemCapability.Communication.NetStack 2271 * @crossplatform 2272 * @since 10 2273 */ 2274 TCPNoDelay?: boolean; 2275 2276 /** 2277 * Socket linger. 2278 * @type { ?object } 2279 * @syscap SystemCapability.Communication.NetStack 2280 * @crossplatform 2281 * @since 7 2282 */ 2283 /** 2284 * Socket linger. 2285 * @type { ?object } 2286 * @syscap SystemCapability.Communication.NetStack 2287 * @crossplatform 2288 * @since 10 2289 */ 2290 socketLinger?: { on: boolean, linger: number }; 2291 } 2292 2293 /** 2294 * Defines a TCPSocket connection. 2295 * @interface TCPSocket 2296 * @syscap SystemCapability.Communication.NetStack 2297 * @since 7 2298 */ 2299 /** 2300 * Defines a TCPSocket connection. 2301 * @interface TCPSocket 2302 * @syscap SystemCapability.Communication.NetStack 2303 * @crossplatform 2304 * @since 10 2305 */ 2306 export interface TCPSocket { 2307 /** 2308 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2309 * @permission ohos.permission.INTERNET 2310 * @param { NetAddress } address - Destination address. {@link NetAddress} 2311 * @param { AsyncCallback<void> } callback - Return the callback of bind. 2312 * @throws { BusinessError } 401 - Parameter error. 2313 * @throws { BusinessError } 201 - Permission denied. 2314 * @syscap SystemCapability.Communication.NetStack 2315 * @since 7 2316 */ 2317 /** 2318 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2319 * @permission ohos.permission.INTERNET 2320 * @param { NetAddress } address - Destination address. {@link NetAddress} 2321 * @param { AsyncCallback<void> } callback - the callback of bind. 2322 * @throws { BusinessError } 401 - Parameter error. 2323 * @throws { BusinessError } 201 - Permission denied. 2324 * @syscap SystemCapability.Communication.NetStack 2325 * @crossplatform 2326 * @since 10 2327 */ 2328 bind(address: NetAddress, callback: AsyncCallback<void>): void; 2329 2330 /** 2331 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2332 * @permission ohos.permission.INTERNET 2333 * @param { NetAddress } address - Destination address. {@link NetAddress} 2334 * @returns { Promise<void> } The promise returned by the function. 2335 * @throws { BusinessError } 401 - Parameter error. 2336 * @throws { BusinessError } 201 - Permission denied. 2337 * @syscap SystemCapability.Communication.NetStack 2338 * @since 7 2339 */ 2340 /** 2341 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2342 * @permission ohos.permission.INTERNET 2343 * @param { NetAddress } address - Destination address. {@link NetAddress} 2344 * @returns { Promise<void> } The promise returned by the function. 2345 * @throws { BusinessError } 401 - Parameter error. 2346 * @throws { BusinessError } 201 - Permission denied. 2347 * @syscap SystemCapability.Communication.NetStack 2348 * @crossplatform 2349 * @since 10 2350 */ 2351 bind(address: NetAddress): Promise<void>; 2352 2353 /** 2354 * Sets up a connection to the specified IP address and port number. 2355 * @permission ohos.permission.INTERNET 2356 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2357 * @param { AsyncCallback<void> } callback - the callback of connect. 2358 * @throws { BusinessError } 401 - Parameter error. 2359 * @throws { BusinessError } 201 - Permission denied. 2360 * @syscap SystemCapability.Communication.NetStack 2361 * @since 7 2362 */ 2363 /** 2364 * Sets up a connection to the specified IP address and port number. 2365 * @permission ohos.permission.INTERNET 2366 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2367 * @param { AsyncCallback<void> } callback - the callback of connect. 2368 * @throws { BusinessError } 401 - Parameter error. 2369 * @throws { BusinessError } 201 - Permission denied. 2370 * @syscap SystemCapability.Communication.NetStack 2371 * @crossplatform 2372 * @since 10 2373 */ 2374 /** 2375 * Sets up a connection to the specified IP address and port number. 2376 * @permission ohos.permission.INTERNET 2377 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2378 * @param { AsyncCallback<void> } callback - the callback of connect. 2379 * @throws { BusinessError } 401 - Parameter error. 2380 * @throws { BusinessError } 201 - Permission denied. 2381 * @throws { BusinessError } 2301206 - Socks5 failed to connect to the proxy server. 2382 * @throws { BusinessError } 2301207 - Socks5 username or password is invalid. 2383 * @throws { BusinessError } 2301208 - Socks5 failed to connect to the remote server. 2384 * @throws { BusinessError } 2301209 - Socks5 failed to negotiate the authentication method. 2385 * @throws { BusinessError } 2301210 - Socks5 failed to send the message. 2386 * @throws { BusinessError } 2301211 - Socks5 failed to receive the message. 2387 * @throws { BusinessError } 2301212 - Socks5 serialization error. 2388 * @throws { BusinessError } 2301213 - Socks5 deserialization error. 2389 * @syscap SystemCapability.Communication.NetStack 2390 * @crossplatform 2391 * @since 18 2392 */ 2393 connect(options: TCPConnectOptions, callback: AsyncCallback<void>): void; 2394 2395 /** 2396 * Sets up a connection to the specified IP address and port number. 2397 * @permission ohos.permission.INTERNET 2398 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2399 * @returns { Promise<void> } The promise returned by the function. 2400 * @throws { BusinessError } 401 - Parameter error. 2401 * @throws { BusinessError } 201 - Permission denied. 2402 * @syscap SystemCapability.Communication.NetStack 2403 * @since 7 2404 */ 2405 /** 2406 * Sets up a connection to the specified IP address and port number. 2407 * @permission ohos.permission.INTERNET 2408 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2409 * @returns { Promise<void> } The promise returned by the function. 2410 * @throws { BusinessError } 401 - Parameter error. 2411 * @throws { BusinessError } 201 - Permission denied. 2412 * @syscap SystemCapability.Communication.NetStack 2413 * @crossplatform 2414 * @since 10 2415 */ 2416 /** 2417 * Sets up a connection to the specified IP address and port number. 2418 * @permission ohos.permission.INTERNET 2419 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 2420 * @returns { Promise<void> } The promise returned by the function. 2421 * @throws { BusinessError } 401 - Parameter error. 2422 * @throws { BusinessError } 201 - Permission denied. 2423 * @throws { BusinessError } 2301206 - Socks5 failed to connect to the proxy server. 2424 * @throws { BusinessError } 2301207 - Socks5 username or password is invalid. 2425 * @throws { BusinessError } 2301208 - Socks5 failed to connect to the remote server. 2426 * @throws { BusinessError } 2301209 - Socks5 failed to negotiate the authentication method. 2427 * @throws { BusinessError } 2301210 - Socks5 failed to send the message. 2428 * @throws { BusinessError } 2301211 - Socks5 failed to receive the message. 2429 * @throws { BusinessError } 2301212 - Socks5 serialization error. 2430 * @throws { BusinessError } 2301213 - Socks5 deserialization error. 2431 * @syscap SystemCapability.Communication.NetStack 2432 * @crossplatform 2433 * @since 18 2434 */ 2435 connect(options: TCPConnectOptions): Promise<void>; 2436 2437 /** 2438 * Sends data over a TCPSocket connection. 2439 * @permission ohos.permission.INTERNET 2440 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 2441 * @param { AsyncCallback<void> } callback - the callback of send. 2442 * @throws { BusinessError } 401 - Parameter error. 2443 * @throws { BusinessError } 201 - Permission denied. 2444 * @syscap SystemCapability.Communication.NetStack 2445 * @since 7 2446 */ 2447 /** 2448 * Sends data over a TCPSocket connection. 2449 * @permission ohos.permission.INTERNET 2450 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 2451 * @param { AsyncCallback<void> } callback - the callback of send. 2452 * @throws { BusinessError } 401 - Parameter error. 2453 * @throws { BusinessError } 201 - Permission denied. 2454 * @syscap SystemCapability.Communication.NetStack 2455 * @crossplatform 2456 * @since 10 2457 */ 2458 send(options: TCPSendOptions, callback: AsyncCallback<void>): void; 2459 2460 /** 2461 * Sends data over a TCPSocket connection. 2462 * @permission ohos.permission.INTERNET 2463 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 2464 * @returns { Promise<void> } The promise returned by the function. 2465 * @throws { BusinessError } 401 - Parameter error. 2466 * @throws { BusinessError } 201 - Permission denied. 2467 * @syscap SystemCapability.Communication.NetStack 2468 * @since 7 2469 */ 2470 /** 2471 * Sends data over a TCPSocket connection. 2472 * @permission ohos.permission.INTERNET 2473 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 2474 * @returns { Promise<void> } The promise returned by the function. 2475 * @throws { BusinessError } 401 - Parameter error. 2476 * @throws { BusinessError } 201 - Permission denied. 2477 * @syscap SystemCapability.Communication.NetStack 2478 * @crossplatform 2479 * @since 10 2480 */ 2481 send(options: TCPSendOptions): Promise<void>; 2482 2483 /** 2484 * Closes a TCPSocket connection. 2485 * @permission ohos.permission.INTERNET 2486 * @param { AsyncCallback<void> } callback - the callback of close. 2487 * @throws { BusinessError } 201 - Permission denied. 2488 * @syscap SystemCapability.Communication.NetStack 2489 * @since 7 2490 */ 2491 /** 2492 * Closes a TCPSocket connection. 2493 * @permission ohos.permission.INTERNET 2494 * @param { AsyncCallback<void> } callback - the callback of close. 2495 * @throws { BusinessError } 201 - Permission denied. 2496 * @syscap SystemCapability.Communication.NetStack 2497 * @crossplatform 2498 * @since 10 2499 */ 2500 close(callback: AsyncCallback<void>): void; 2501 2502 /** 2503 * Closes a TCPSocket connection. 2504 * @permission ohos.permission.INTERNET 2505 * @returns { Promise<void> } The promise returned by the function. 2506 * @throws { BusinessError } 201 - Permission denied. 2507 * @syscap SystemCapability.Communication.NetStack 2508 * @since 7 2509 */ 2510 /** 2511 * Closes a TCPSocket connection. 2512 * @permission ohos.permission.INTERNET 2513 * @returns { Promise<void> } The promise returned by the function. 2514 * @throws { BusinessError } 201 - Permission denied. 2515 * @syscap SystemCapability.Communication.NetStack 2516 * @crossplatform 2517 * @since 10 2518 */ 2519 close(): Promise<void>; 2520 2521 /** 2522 * Obtains the peer address of a TCPSocket connection. 2523 * @permission ohos.permission.INTERNET 2524 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress} 2525 * @throws { BusinessError } 201 - Permission denied. 2526 * @syscap SystemCapability.Communication.NetStack 2527 * @since 7 2528 */ 2529 /** 2530 * Obtains the peer address of a TCPSocket connection. 2531 * @permission ohos.permission.INTERNET 2532 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress} 2533 * @throws { BusinessError } 201 - Permission denied. 2534 * @syscap SystemCapability.Communication.NetStack 2535 * @crossplatform 2536 * @since 10 2537 */ 2538 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 2539 2540 /** 2541 * Obtains the peer address of a TCPSocket connection. 2542 * @permission ohos.permission.INTERNET 2543 * @returns { Promise<NetAddress> } The promise returned by the function. 2544 * @throws { BusinessError } 201 - Permission denied. 2545 * @syscap SystemCapability.Communication.NetStack 2546 * @since 7 2547 */ 2548 /** 2549 * Obtains the peer address of a TCPSocket connection. 2550 * @permission ohos.permission.INTERNET 2551 * @returns { Promise<NetAddress> } The promise returned by the function. 2552 * @throws { BusinessError } 201 - Permission denied. 2553 * @syscap SystemCapability.Communication.NetStack 2554 * @crossplatform 2555 * @since 10 2556 */ 2557 getRemoteAddress(): Promise<NetAddress>; 2558 2559 /** 2560 * Obtains the status of the TCPSocket connection. 2561 * @permission ohos.permission.INTERNET 2562 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase} 2563 * @throws { BusinessError } 201 - Permission denied. 2564 * @syscap SystemCapability.Communication.NetStack 2565 * @since 7 2566 */ 2567 /** 2568 * Obtains the status of the TCPSocket connection. 2569 * @permission ohos.permission.INTERNET 2570 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase} 2571 * @throws { BusinessError } 201 - Permission denied. 2572 * @syscap SystemCapability.Communication.NetStack 2573 * @crossplatform 2574 * @since 10 2575 */ 2576 getState(callback: AsyncCallback<SocketStateBase>): void; 2577 2578 /** 2579 * Obtains the status of the TCPSocket connection. 2580 * @permission ohos.permission.INTERNET 2581 * @returns { Promise<SocketStateBase> } The promise returned by the function. 2582 * @throws { BusinessError } 201 - Permission denied. 2583 * @syscap SystemCapability.Communication.NetStack 2584 * @since 7 2585 */ 2586 /** 2587 * Obtains the status of the TCPSocket connection. 2588 * @permission ohos.permission.INTERNET 2589 * @returns { Promise<SocketStateBase> } The promise returned by the function. 2590 * @throws { BusinessError } 201 - Permission denied. 2591 * @syscap SystemCapability.Communication.NetStack 2592 * @crossplatform 2593 * @since 10 2594 */ 2595 getState(): Promise<SocketStateBase>; 2596 2597 /** 2598 * Obtains the file descriptor of the TCPSocket connection. 2599 * @param { AsyncCallback<number> } callback - The callback returns the file descriptor of the TCPSocket connection. 2600 * @syscap SystemCapability.Communication.NetStack 2601 * @since 10 2602 */ 2603 getSocketFd(callback: AsyncCallback<number>): void; 2604 2605 /** 2606 * Obtains the file descriptor of the TCPSocket connection. 2607 * @returns { Promise<number> } The promise returns the file descriptor of the TCPSocket connection. 2608 * @syscap SystemCapability.Communication.NetStack 2609 * @since 10 2610 */ 2611 getSocketFd(): Promise<number>; 2612 2613 /** 2614 * Sets other attributes of the TCPSocket connection. 2615 * @permission ohos.permission.INTERNET 2616 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2617 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 2618 * @throws { BusinessError } 401 - Parameter error. 2619 * @throws { BusinessError } 201 - Permission denied. 2620 * @syscap SystemCapability.Communication.NetStack 2621 * @since 7 2622 */ 2623 /** 2624 * Sets other attributes of the TCPSocket connection. 2625 * @permission ohos.permission.INTERNET 2626 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2627 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 2628 * @throws { BusinessError } 401 - Parameter error. 2629 * @throws { BusinessError } 201 - Permission denied. 2630 * @syscap SystemCapability.Communication.NetStack 2631 * @crossplatform 2632 * @since 10 2633 */ 2634 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 2635 2636 /** 2637 * Sets other attributes of the TCPSocket connection. 2638 * @permission ohos.permission.INTERNET 2639 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2640 * @returns { Promise<void> } The promise returned by the function. 2641 * @throws { BusinessError } 401 - Parameter error. 2642 * @throws { BusinessError } 201 - Permission denied. 2643 * @syscap SystemCapability.Communication.NetStack 2644 * @since 7 2645 */ 2646 /** 2647 * Sets other attributes of the TCPSocket connection. 2648 * @permission ohos.permission.INTERNET 2649 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2650 * @returns { Promise<void> } The promise returned by the function. 2651 * @throws { BusinessError } 401 - Parameter error. 2652 * @throws { BusinessError } 201 - Permission denied. 2653 * @syscap SystemCapability.Communication.NetStack 2654 * @crossplatform 2655 * @since 10 2656 */ 2657 setExtraOptions(options: TCPExtraOptions): Promise<void>; 2658 2659 /** 2660 * Obtains the local address of a TCPSocket connection. 2661 * @returns { Promise<NetAddress> } The promise returned by the function. 2662 * @throws { BusinessError } 2300002 - System internal error. 2663 * @throws { BusinessError } 2301009 - Bad file descriptor. 2664 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2665 * @syscap SystemCapability.Communication.NetStack 2666 * @since 12 2667 */ 2668 getLocalAddress(): Promise<NetAddress>; 2669 2670 /** 2671 * Listens for message receiving events of the TCPSocket connection. 2672 * @param { 'message' } type - Indicates Event name. 2673 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 2674 * @syscap SystemCapability.Communication.NetStack 2675 * @since 7 2676 */ 2677 /** 2678 * Listens for message receiving events of the TCPSocket connection. 2679 * @param { 'message' } type Indicates Event name. 2680 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 2681 * @syscap SystemCapability.Communication.NetStack 2682 * @crossplatform 2683 * @since 10 2684 */ 2685 /** 2686 * Listens for message receiving events of the TCPSocket connection. 2687 * @param { 'message' } type Indicates Event name. 2688 * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result. 2689 * @syscap SystemCapability.Communication.NetStack 2690 * @crossplatform 2691 * @since 11 2692 */ 2693 on(type: 'message', callback: Callback<SocketMessageInfo>): void; 2694 2695 /** 2696 * Cancels listening for message receiving events of the TCPSocket connection. 2697 * @param { 'message' } type Indicates Event name. 2698 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 2699 * @syscap SystemCapability.Communication.NetStack 2700 * @since 7 2701 */ 2702 /** 2703 * Cancels listening for message receiving events of the TCPSocket connection. 2704 * @param { 'message' } type Indicates Event name. 2705 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 2706 * @syscap SystemCapability.Communication.NetStack 2707 * @crossplatform 2708 * @since 10 2709 */ 2710 /** 2711 * Cancels listening for message receiving events of the TCPSocket connection. 2712 * @param { 'message' } type Indicates Event name. 2713 * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result. 2714 * @syscap SystemCapability.Communication.NetStack 2715 * @crossplatform 2716 * @since 11 2717 */ 2718 off(type: 'message', callback?: Callback<SocketMessageInfo>): void; 2719 2720 2721 /** 2722 * Listens for connection or close events of the TCPSocket connection. 2723 * @param { 'connect' | 'close' } type - Indicates Event name. 2724 * @param { Callback<void> } callback - the callback used to return the result. 2725 * @syscap SystemCapability.Communication.NetStack 2726 * @since 7 2727 */ 2728 /** 2729 * Listens for connection or close events of the TCPSocket connection. 2730 * @param { 'connect' | 'close' } type - Indicates Event name. 2731 * @param { Callback<void> } callback - the callback used to return the result. 2732 * @syscap SystemCapability.Communication.NetStack 2733 * @crossplatform 2734 * @since 10 2735 */ 2736 on(type: 'connect' | 'close', callback: Callback<void>): void; 2737 2738 /** 2739 * Cancels listening for connection or close events of the TCPSocket connection. 2740 * @param { 'connect' | 'close' } type - Indicates Event name. 2741 * @param { Callback<void> } callback - the callback used to return the result. 2742 * @syscap SystemCapability.Communication.NetStack 2743 * @since 7 2744 */ 2745 /** 2746 * Cancels listening for connection or close events of the TCPSocket connection. 2747 * @param { 'connect' | 'close' } type - Indicates Event name. 2748 * @param { Callback<void> } callback - the callback used to return the result. 2749 * @syscap SystemCapability.Communication.NetStack 2750 * @crossplatform 2751 * @since 10 2752 */ 2753 off(type: 'connect' | 'close', callback?: Callback<void>): void; 2754 2755 /** 2756 * Listens for error events of the TCPSocket connection. 2757 * @param { 'error' } type - Indicates Event name. 2758 * @param { ErrorCallback } callback - the callback used to return the result. 2759 * @syscap SystemCapability.Communication.NetStack 2760 * @since 7 2761 */ 2762 /** 2763 * Listens for error events of the TCPSocket connection. 2764 * @param { 'error' } type - Indicates Event name. 2765 * @param { ErrorCallback } callback - the callback used to return the result. 2766 * @syscap SystemCapability.Communication.NetStack 2767 * @crossplatform 2768 * @since 10 2769 */ 2770 on(type: 'error', callback: ErrorCallback): void; 2771 2772 /** 2773 * Cancels listening for error events of the TCPSocket connection. 2774 * @param { 'error' } type - Indicates Event name. 2775 * @param { ErrorCallback } callback - the callback used to return the result. 2776 * @syscap SystemCapability.Communication.NetStack 2777 * @since 7 2778 */ 2779 /** 2780 * Cancels listening for error events of the TCPSocket connection. 2781 * @param { 'error' } type - Indicates Event name. 2782 * @param { ErrorCallback } callback - the callback used to return the result. 2783 * @syscap SystemCapability.Communication.NetStack 2784 * @crossplatform 2785 * @since 10 2786 */ 2787 off(type: 'error', callback?: ErrorCallback): void; 2788 } 2789 2790 /** 2791 * Defines a TLSSocket connection. 2792 * @interface TLSSocket 2793 * @syscap SystemCapability.Communication.NetStack 2794 * @since 9 2795 */ 2796 /** 2797 * Defines a TLSSocket connection. 2798 * @interface TLSSocket 2799 * @syscap SystemCapability.Communication.NetStack 2800 * @crossplatform 2801 * @since 10 2802 */ 2803 export interface TLSSocket { 2804 /** 2805 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2806 * @permission ohos.permission.INTERNET 2807 * @param { NetAddress } address - Destination address. {@link NetAddress} 2808 * @param { AsyncCallback<void> } callback - the callback of bind. 2809 * @throws { BusinessError } 401 - Parameter error. 2810 * @throws { BusinessError } 201 - Permission denied. 2811 * @throws { BusinessError } 2303198 - Address already in use. 2812 * @throws { BusinessError } 2300002 - System internal error. 2813 * @syscap SystemCapability.Communication.NetStack 2814 * @since 9 2815 */ 2816 /** 2817 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2818 * @permission ohos.permission.INTERNET 2819 * @param { NetAddress } address - Destination address. {@link NetAddress} 2820 * @param { AsyncCallback<void> } callback - the callback of bind. 2821 * @throws { BusinessError } 401 - Parameter error. 2822 * @throws { BusinessError } 201 - Permission denied. 2823 * @throws { BusinessError } 2303198 - Address already in use. 2824 * @throws { BusinessError } 2300002 - System internal error. 2825 * @syscap SystemCapability.Communication.NetStack 2826 * @crossplatform 2827 * @since 10 2828 */ 2829 bind(address: NetAddress, callback: AsyncCallback<void>): void; 2830 2831 /** 2832 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2833 * @permission ohos.permission.INTERNET 2834 * @param { NetAddress } address - Destination address. {@link NetAddress} 2835 * @returns { Promise<void> } The promise returned by the function. 2836 * @throws { BusinessError } 401 - Parameter error. 2837 * @throws { BusinessError } 201 - Permission denied. 2838 * @throws { BusinessError } 2303198 - Address already in use. 2839 * @throws { BusinessError } 2300002 - System internal error. 2840 * @syscap SystemCapability.Communication.NetStack 2841 * @since 9 2842 */ 2843 /** 2844 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 2845 * @permission ohos.permission.INTERNET 2846 * @param { NetAddress } address - Destination address. {@link NetAddress} 2847 * @returns { Promise<void> } The promise returned by the function. 2848 * @throws { BusinessError } 401 - Parameter error. 2849 * @throws { BusinessError } 201 - Permission denied. 2850 * @throws { BusinessError } 2303198 - Address already in use. 2851 * @throws { BusinessError } 2300002 - System internal error. 2852 * @syscap SystemCapability.Communication.NetStack 2853 * @crossplatform 2854 * @since 10 2855 */ 2856 bind(address: NetAddress): Promise<void>; 2857 2858 /** 2859 * Obtains the peer address of a TLSSocket connection. 2860 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. 2861 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2862 * @throws { BusinessError } 2300002 - System internal error. 2863 * @syscap SystemCapability.Communication.NetStack 2864 * @since 9 2865 */ 2866 /** 2867 * Obtains the peer address of a TLSSocket connection. 2868 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. 2869 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2870 * @throws { BusinessError } 2300002 - System internal error. 2871 * @syscap SystemCapability.Communication.NetStack 2872 * @crossplatform 2873 * @since 10 2874 */ 2875 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 2876 2877 /** 2878 * Obtains the peer address of a TLSSocket connection. 2879 * @returns { Promise<NetAddress> } The promise returned by the function. 2880 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2881 * @throws { BusinessError } 2300002 - System internal error. 2882 * @syscap SystemCapability.Communication.NetStack 2883 * @since 9 2884 */ 2885 /** 2886 * Obtains the peer address of a TLSSocket connection. 2887 * @returns { Promise<NetAddress> } The promise returned by the function. 2888 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2889 * @throws { BusinessError } 2300002 - System internal error. 2890 * @syscap SystemCapability.Communication.NetStack 2891 * @crossplatform 2892 * @since 10 2893 */ 2894 getRemoteAddress(): Promise<NetAddress>; 2895 2896 /** 2897 * Obtains the status of the TLSSocket connection. 2898 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. 2899 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2900 * @throws { BusinessError } 2300002 - System internal error. 2901 * @syscap SystemCapability.Communication.NetStack 2902 * @since 9 2903 */ 2904 /** 2905 * Obtains the status of the TLSSocket connection. 2906 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. 2907 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2908 * @throws { BusinessError } 2300002 - System internal error. 2909 * @syscap SystemCapability.Communication.NetStack 2910 * @crossplatform 2911 * @since 10 2912 */ 2913 getState(callback: AsyncCallback<SocketStateBase>): void; 2914 2915 /** 2916 * Obtains the status of the TLSSocket connection. 2917 * @returns { Promise<SocketStateBase> } The promise returned by the function. 2918 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2919 * @throws { BusinessError } 2300002 - System internal error. 2920 * @syscap SystemCapability.Communication.NetStack 2921 * @since 9 2922 */ 2923 /** 2924 * Obtains the status of the TLSSocket connection. 2925 * @returns { Promise<SocketStateBase> } The promise returned by the function. 2926 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2927 * @throws { BusinessError } 2300002 - System internal error. 2928 * @syscap SystemCapability.Communication.NetStack 2929 * @crossplatform 2930 * @since 10 2931 */ 2932 getState(): Promise<SocketStateBase>; 2933 2934 /** 2935 * Sets other attributes of the TLSSocket connection. 2936 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2937 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 2938 * @throws { BusinessError } 401 - Parameter error. 2939 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2940 * @throws { BusinessError } 2300002 - System internal error. 2941 * @syscap SystemCapability.Communication.NetStack 2942 * @since 9 2943 */ 2944 /** 2945 * Sets other attributes of the TLSSocket connection. 2946 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2947 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 2948 * @throws { BusinessError } 401 - Parameter error. 2949 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2950 * @throws { BusinessError } 2300002 - System internal error. 2951 * @syscap SystemCapability.Communication.NetStack 2952 * @crossplatform 2953 * @since 10 2954 */ 2955 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 2956 2957 /** 2958 * Sets other attributes of the TLSSocket connection. 2959 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2960 * @returns { Promise<void> } The promise returned by the function. 2961 * @throws { BusinessError } 401 - Parameter error. 2962 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2963 * @throws { BusinessError } 2300002 - System internal error. 2964 * @syscap SystemCapability.Communication.NetStack 2965 * @since 9 2966 */ 2967 /** 2968 * Sets other attributes of the TLSSocket connection. 2969 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 2970 * @returns { Promise<void> } The promise returned by the function. 2971 * @throws { BusinessError } 401 - Parameter error. 2972 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2973 * @throws { BusinessError } 2300002 - System internal error. 2974 * @syscap SystemCapability.Communication.NetStack 2975 * @crossplatform 2976 * @since 10 2977 */ 2978 setExtraOptions(options: TCPExtraOptions): Promise<void>; 2979 2980 /** 2981 * Obtains the local address of a TLSSocket connection. 2982 * @returns { Promise<NetAddress> } The promise returned by the function. 2983 * @throws { BusinessError } 2300002 - System internal error. 2984 * @throws { BusinessError } 2301009 - Bad file descriptor. 2985 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2986 * @syscap SystemCapability.Communication.NetStack 2987 * @since 12 2988 */ 2989 getLocalAddress(): Promise<NetAddress>; 2990 2991 /** 2992 * Listens for message receiving events of the TLSSocket connection. 2993 * @param { 'message' } type - Indicates Event name. 2994 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 2995 * @throws { BusinessError } 401 - Parameter error. 2996 * @syscap SystemCapability.Communication.NetStack 2997 * @since 9 2998 */ 2999 /** 3000 * Listens for message receiving events of the TLSSocket connection. 3001 * @param { 'message' } type Indicates Event name. 3002 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 3003 * @throws { BusinessError } 401 - Parameter error. 3004 * @syscap SystemCapability.Communication.NetStack 3005 * @crossplatform 3006 * @since 10 3007 */ 3008 /** 3009 * Listens for message receiving events of the TLSSocket connection. 3010 * @param { 'message' } type Indicates Event name. 3011 * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result. 3012 * @throws { BusinessError } 401 - Parameter error. 3013 * @syscap SystemCapability.Communication.NetStack 3014 * @crossplatform 3015 * @since 11 3016 */ 3017 on(type: 'message', callback: Callback<SocketMessageInfo>): void; 3018 3019 /** 3020 * Cancels listening for message receiving events of the TLSSocket connection. 3021 * @param { 'message' } type - Indicates Event name. 3022 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 3023 * @throws { BusinessError } 401 - Parameter error. 3024 * @syscap SystemCapability.Communication.NetStack 3025 * @since 9 3026 */ 3027 /** 3028 * Cancels listening for message receiving events of the TLSSocket connection. 3029 * @param { 'message' } type Indicates Event name. 3030 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 3031 * @throws { BusinessError } 401 - Parameter error. 3032 * @syscap SystemCapability.Communication.NetStack 3033 * @crossplatform 3034 * @since 10 3035 */ 3036 /** 3037 * Cancels listening for message receiving events of the TLSSocket connection. 3038 * @param { 'message' } type Indicates Event name. 3039 * @param { Callback<SocketMessageInfo> } callback - the callback used to return the result. 3040 * @throws { BusinessError } 401 - Parameter error. 3041 * @syscap SystemCapability.Communication.NetStack 3042 * @crossplatform 3043 * @since 11 3044 */ 3045 off(type: 'message', callback?: Callback<SocketMessageInfo>): void; 3046 3047 /** 3048 * Listens for connection or close events of the TLSSocket connection. 3049 * @param { 'connect' | 'close' } type - Indicates Event name. 3050 * @param {Callback<void> } callback - the callback used to return the result. 3051 * @throws { BusinessError } 401 - Parameter error. 3052 * @syscap SystemCapability.Communication.NetStack 3053 * @since 9 3054 */ 3055 /** 3056 * Listens for connection or close events of the TLSSocket connection. 3057 * @param { 'connect' | 'close' } type - Indicates Event name. 3058 * @param {Callback<void> } callback - the callback used to return the result. 3059 * @throws { BusinessError } 401 - Parameter error. 3060 * @syscap SystemCapability.Communication.NetStack 3061 * @crossplatform 3062 * @since 10 3063 */ 3064 on(type: 'connect' | 'close', callback: Callback<void>): void; 3065 3066 /** 3067 * Cancels listening for connection or close events of the TLSSocket connection. 3068 * @param { 'connect' | 'close' } type - Indicates Event name. 3069 * @param {Callback<void> } callback - the callback used to return the result. 3070 * @throws { BusinessError } 401 - Parameter error. 3071 * @syscap SystemCapability.Communication.NetStack 3072 * @since 9 3073 */ 3074 /** 3075 * Cancels listening for connection or close events of the TLSSocket connection. 3076 * @param { 'connect' | 'close' } type - Indicates Event name. 3077 * @param {Callback<void> } callback - the callback used to return the result. 3078 * @throws { BusinessError } 401 - Parameter error. 3079 * @syscap SystemCapability.Communication.NetStack 3080 * @crossplatform 3081 * @since 10 3082 */ 3083 off(type: 'connect' | 'close', callback?: Callback<void>): void; 3084 3085 /** 3086 * Listens for error events of the TLSSocket connection. 3087 * @param { 'error' } type - Indicates Event name. 3088 * @param { ErrorCallback } callback - the callback used to return the result. 3089 * @throws { BusinessError } 401 - Parameter error. 3090 * @syscap SystemCapability.Communication.NetStack 3091 * @since 9 3092 */ 3093 /** 3094 * Listens for error events of the TLSSocket connection. 3095 * @param { 'error' } type - Indicates Event name. 3096 * @param { ErrorCallback } callback - the callback used to return the result. 3097 * @throws { BusinessError } 401 - Parameter error. 3098 * @syscap SystemCapability.Communication.NetStack 3099 * @crossplatform 3100 * @since 10 3101 */ 3102 on(type: 'error', callback: ErrorCallback): void; 3103 3104 /** 3105 * Cancels listening for error events of the TLSSocket connection. 3106 * @param { 'error' } type - Indicates Event name. 3107 * @param { ErrorCallback } callback - the callback used to return the result. 3108 * @throws { BusinessError } 401 - Parameter error. 3109 * @syscap SystemCapability.Communication.NetStack 3110 * @since 9 3111 */ 3112 /** 3113 * Cancels listening for error events of the TLSSocket connection. 3114 * @param { 'error' } type - Indicates Event name. 3115 * @param { ErrorCallback } callback - the callback used to return the result. 3116 * @throws { BusinessError } 401 - Parameter error. 3117 * @syscap SystemCapability.Communication.NetStack 3118 * @crossplatform 3119 * @since 10 3120 */ 3121 off(type: 'error', callback?: ErrorCallback): void; 3122 3123 /** 3124 * Returns an object representing a local certificate. 3125 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate. 3126 * @throws { BusinessError } 2303501 - SSL is null. 3127 * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate. 3128 * @throws { BusinessError } 2300002 - System internal error. 3129 * @syscap SystemCapability.Communication.NetStack 3130 * @since 9 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 * @crossplatform 3140 * @since 10 3141 */ 3142 getCertificate(callback: AsyncCallback<X509CertRawData>): void; 3143 3144 /** 3145 * Returns an object representing a local certificate. 3146 * @returns { Promise<X509CertRawData> } The promise returned by the function. 3147 * @throws { BusinessError } 2303501 - SSL is null. 3148 * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate. 3149 * @throws { BusinessError } 2300002 - System internal error. 3150 * @syscap SystemCapability.Communication.NetStack 3151 * @since 9 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 * @crossplatform 3161 * @since 10 3162 */ 3163 getCertificate(): Promise<X509CertRawData>; 3164 3165 /** 3166 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 3167 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 3168 * It only contains the peer's certificate. 3169 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate. 3170 * @throws { BusinessError } 2303501 - SSL is null. 3171 * @throws { BusinessError } 2300002 - System internal error. 3172 * @syscap SystemCapability.Communication.NetStack 3173 * @since 9 3174 */ 3175 /** 3176 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 3177 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 3178 * It only contains the peer's certificate. 3179 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate. 3180 * @throws { BusinessError } 2303501 - SSL is null. 3181 * @throws { BusinessError } 2300002 - System internal error. 3182 * @syscap SystemCapability.Communication.NetStack 3183 * @crossplatform 3184 * @since 10 3185 */ 3186 getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void; 3187 3188 /** 3189 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 3190 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 3191 * It only contains the peer's certificate. 3192 * @returns { Promise<X509CertRawData> } The promise returned by the function. 3193 * @throws { BusinessError } 2303501 - SSL is null. 3194 * @throws { BusinessError } 2300002 - System internal error. 3195 * @syscap SystemCapability.Communication.NetStack 3196 * @since 9 3197 */ 3198 /** 3199 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 3200 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 3201 * It only contains the peer's certificate. 3202 * @returns { Promise<X509CertRawData> } The promise returned by the function. 3203 * @throws { BusinessError } 2303501 - SSL is null. 3204 * @throws { BusinessError } 2300002 - System internal error. 3205 * @syscap SystemCapability.Communication.NetStack 3206 * @crossplatform 3207 * @since 10 3208 */ 3209 getRemoteCertificate(): Promise<X509CertRawData>; 3210 3211 /** 3212 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3213 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3214 * Server sockets or disconnected client sockets will return a value of null. 3215 * @param { AsyncCallback<string> } callback - the callback of getProtocol. 3216 * @throws { BusinessError } 2303501 - SSL is null. 3217 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3218 * @throws { BusinessError } 2300002 - System internal error. 3219 * @syscap SystemCapability.Communication.NetStack 3220 * @since 9 3221 */ 3222 /** 3223 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3224 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3225 * Server sockets or disconnected client sockets will return a value of null. 3226 * @param { AsyncCallback<string> } callback - the callback of getProtocol. 3227 * @throws { BusinessError } 2303501 - SSL is null. 3228 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3229 * @throws { BusinessError } 2300002 - System internal error. 3230 * @syscap SystemCapability.Communication.NetStack 3231 * @crossplatform 3232 * @since 10 3233 */ 3234 getProtocol(callback: AsyncCallback<string>): void; 3235 3236 /** 3237 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3238 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3239 * Server sockets or disconnected client sockets will return a value of null. 3240 * @returns { Promise<string> } The promise returned by the function. 3241 * @throws { BusinessError } 2303501 - SSL is null. 3242 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3243 * @throws { BusinessError } 2300002 - System internal error. 3244 * @syscap SystemCapability.Communication.NetStack 3245 * @since 9 3246 */ 3247 /** 3248 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3249 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3250 * Server sockets or disconnected client sockets will return a value of null. 3251 * @returns { Promise<string> } The promise returned by the function. 3252 * @throws { BusinessError } 2303501 - SSL is null. 3253 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3254 * @throws { BusinessError } 2300002 - System internal error. 3255 * @syscap SystemCapability.Communication.NetStack 3256 * @crossplatform 3257 * @since 10 3258 */ 3259 getProtocol(): Promise<string>; 3260 3261 /** 3262 * Returns a list containing the negotiated cipher suite information. 3263 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 3264 * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite. 3265 * @throws { BusinessError } 2303501 - SSL is null. 3266 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3267 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3268 * @throws { BusinessError } 2300002 - System internal error. 3269 * @syscap SystemCapability.Communication.NetStack 3270 * @since 9 3271 */ 3272 /** 3273 * Returns a list containing the negotiated cipher suite information. 3274 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 3275 * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite. 3276 * @throws { BusinessError } 2303501 - SSL is null. 3277 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3278 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3279 * @throws { BusinessError } 2300002 - System internal error. 3280 * @syscap SystemCapability.Communication.NetStack 3281 * @crossplatform 3282 * @since 10 3283 */ 3284 getCipherSuite(callback: AsyncCallback<Array<string>>): void; 3285 3286 /** 3287 * Returns a list containing the negotiated cipher suite information. 3288 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 3289 * @returns { Promise<Array<string>> } The promise returned by the function. 3290 * @throws { BusinessError } 2303501 - SSL is null. 3291 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3292 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3293 * @throws { BusinessError } 2300002 - System internal error. 3294 * @syscap SystemCapability.Communication.NetStack 3295 * @since 9 3296 */ 3297 /** 3298 * Returns a list containing the negotiated cipher suite information. 3299 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 3300 * @returns { Promise<Array<string>> } The promise returned by the function. 3301 * @throws { BusinessError } 2303501 - SSL is null. 3302 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3303 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3304 * @throws { BusinessError } 2300002 - System internal error. 3305 * @syscap SystemCapability.Communication.NetStack 3306 * @crossplatform 3307 * @since 10 3308 */ 3309 getCipherSuite(): Promise<Array<string>>; 3310 3311 /** 3312 * <p>The list of signature algorithms shared between the server and the client, 3313 * in descending order of priority.</p> 3314 * @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html 3315 * @throws { BusinessError } 2303501 - SSL is null. 3316 * @throws { BusinessError } 2300002 - System internal error. 3317 * @syscap SystemCapability.Communication.NetStack 3318 * @since 9 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 * @crossplatform 3328 * @since 10 3329 */ 3330 getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void; 3331 3332 /** 3333 * <p>The list of signature algorithms shared between the server and the client, 3334 * in descending order of priority.</p> 3335 * @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 3336 * @throws { BusinessError } 2303501 - SSL is null. 3337 * @throws { BusinessError } 2300002 - System internal error. 3338 * @syscap SystemCapability.Communication.NetStack 3339 * @since 9 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 * @crossplatform 3349 * @since 10 3350 */ 3351 getSignatureAlgorithms(): Promise<Array<string>>; 3352 3353 /** 3354 * Obtains the file descriptor of the TLSSocket connection. 3355 * @returns { Promise<number> } The promise returns the file descriptor of the TLSSocket connection. 3356 * @syscap SystemCapability.Communication.NetStack 3357 * @since 16 3358 */ 3359 getSocketFd(): Promise<number>; 3360 3361 /** 3362 * Sets up a connection to the specified IP address and port number. 3363 * Only TCP is supported. 3364 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3365 * @param { AsyncCallback<void> } callback - the callback of connect. 3366 * @throws { BusinessError } 401 - Parameter error. 3367 * @throws { BusinessError } 2303104 - Interrupted system call. 3368 * @throws { BusinessError } 2303109 - Bad file number. 3369 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3370 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3371 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3372 * @throws { BusinessError } 2303198 - Address already in use. 3373 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3374 * @throws { BusinessError } 2303210 - Connection timed out. 3375 * @throws { BusinessError } 2303501 - SSL is null. 3376 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3377 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3378 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3379 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3380 * @throws { BusinessError } 2300002 - System internal error. 3381 * @syscap SystemCapability.Communication.NetStack 3382 * @since 9 3383 */ 3384 /** 3385 * Sets up a connection to the specified IP address and port number. 3386 * Only TCP is supported. 3387 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3388 * @param { AsyncCallback<void> } callback - the callback of connect. 3389 * @throws { BusinessError } 401 - Parameter error. 3390 * @throws { BusinessError } 2303104 - Interrupted system call. 3391 * @throws { BusinessError } 2303109 - Bad file number. 3392 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3393 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3394 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3395 * @throws { BusinessError } 2303198 - Address already in use. 3396 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3397 * @throws { BusinessError } 2303210 - Connection timed out. 3398 * @throws { BusinessError } 2303501 - SSL is null. 3399 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3400 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3401 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3402 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3403 * @throws { BusinessError } 2300002 - System internal error. 3404 * @syscap SystemCapability.Communication.NetStack 3405 * @crossplatform 3406 * @since 10 3407 */ 3408 /** 3409 * Sets up a connection to the specified IP address and port number. 3410 * Only TCP is supported. 3411 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3412 * @param { AsyncCallback<void> } callback - the callback of connect. 3413 * @throws { BusinessError } 401 - Parameter error. 3414 * @throws { BusinessError } 2303104 - Interrupted system call. 3415 * @throws { BusinessError } 2303109 - Bad file number. 3416 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3417 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3418 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3419 * @throws { BusinessError } 2303198 - Address already in use. 3420 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3421 * @throws { BusinessError } 2303210 - Connection timed out. 3422 * @throws { BusinessError } 2303501 - SSL is null. 3423 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3424 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3425 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3426 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3427 * @throws { BusinessError } 2300002 - System internal error. 3428 * @throws { BusinessError } 2301206 - Socks5 failed to connect to the proxy server. 3429 * @throws { BusinessError } 2301207 - Socks5 username or password is invalid. 3430 * @throws { BusinessError } 2301208 - Socks5 failed to connect to the remote server. 3431 * @throws { BusinessError } 2301209 - Socks5 failed to negotiate the authentication method. 3432 * @throws { BusinessError } 2301210 - Socks5 failed to send the message. 3433 * @throws { BusinessError } 2301211 - Socks5 failed to receive the message. 3434 * @throws { BusinessError } 2301212 - Socks5 serialization error. 3435 * @throws { BusinessError } 2301213 - Socks5 deserialization error. 3436 * @syscap SystemCapability.Communication.NetStack 3437 * @crossplatform 3438 * @since 18 3439 */ 3440 connect(options: TLSConnectOptions, callback: AsyncCallback<void>): void; 3441 3442 /** 3443 * Sets up a connection to the specified IP address and port number. 3444 * Only TCP is supported. 3445 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3446 * @returns { Promise<void> } The promise returned by the function. 3447 * @throws { BusinessError } 401 - Parameter error. 3448 * @throws { BusinessError } 2303104 - Interrupted system call. 3449 * @throws { BusinessError } 2303109 - Bad file number. 3450 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3451 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3452 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3453 * @throws { BusinessError } 2303198 - Address already in use. 3454 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3455 * @throws { BusinessError } 2303210 - Connection timed out. 3456 * @throws { BusinessError } 2303501 - SSL is null. 3457 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3458 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3459 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3460 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3461 * @throws { BusinessError } 2300002 - System internal error. 3462 * @syscap SystemCapability.Communication.NetStack 3463 * @since 9 3464 */ 3465 /** 3466 * Sets up a connection to the specified IP address and port number. 3467 * Only TCP is supported. 3468 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3469 * @returns { Promise<void> } The promise returned by the function. 3470 * @throws { BusinessError } 401 - Parameter error. 3471 * @throws { BusinessError } 2303104 - Interrupted system call. 3472 * @throws { BusinessError } 2303109 - Bad file number. 3473 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3474 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3475 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3476 * @throws { BusinessError } 2303198 - Address already in use. 3477 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3478 * @throws { BusinessError } 2303210 - Connection timed out. 3479 * @throws { BusinessError } 2303501 - SSL is null. 3480 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3481 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3482 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3483 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3484 * @throws { BusinessError } 2300002 - System internal error. 3485 * @syscap SystemCapability.Communication.NetStack 3486 * @crossplatform 3487 * @since 10 3488 */ 3489 /** 3490 * Sets up a connection to the specified IP address and port number. 3491 * Only TCP is supported. 3492 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 3493 * @returns { Promise<void> } The promise returned by the function. 3494 * @throws { BusinessError } 401 - Parameter error. 3495 * @throws { BusinessError } 2303104 - Interrupted system call. 3496 * @throws { BusinessError } 2303109 - Bad file number. 3497 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 3498 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3499 * @throws { BusinessError } 2303191 - Incorrect socket protocol type. 3500 * @throws { BusinessError } 2303198 - Address already in use. 3501 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3502 * @throws { BusinessError } 2303210 - Connection timed out. 3503 * @throws { BusinessError } 2303501 - SSL is null. 3504 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 3505 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3506 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3507 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3508 * @throws { BusinessError } 2300002 - System internal error. 3509 * @throws { BusinessError } 2301206 - Socks5 failed to connect to the proxy server. 3510 * @throws { BusinessError } 2301207 - Socks5 username or password is invalid. 3511 * @throws { BusinessError } 2301208 - Socks5 failed to connect to the remote server. 3512 * @throws { BusinessError } 2301209 - Socks5 failed to negotiate the authentication method. 3513 * @throws { BusinessError } 2301210 - Socks5 failed to send the message. 3514 * @throws { BusinessError } 2301211 - Socks5 failed to receive the message. 3515 * @throws { BusinessError } 2301212 - Socks5 serialization error. 3516 * @throws { BusinessError } 2301213 - Socks5 deserialization error. 3517 * @syscap SystemCapability.Communication.NetStack 3518 * @crossplatform 3519 * @since 18 3520 */ 3521 connect(options: TLSConnectOptions): Promise<void>; 3522 3523 /** 3524 * Sends data over a TLSSocket connection. 3525 * @param { string } data - Parameters for sending data {@link string}. 3526 * @param { AsyncCallback<void> } callback - the callback of send. 3527 * @throws { BusinessError } 401 - Parameter error. 3528 * @throws { BusinessError } 2303501 - SSL is null. 3529 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3530 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3531 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3532 * @throws { BusinessError } 2300002 - System internal error. 3533 * @syscap SystemCapability.Communication.NetStack 3534 * @since 9 3535 */ 3536 /** 3537 * Sends data over a TLSSocket connection. 3538 * @param { string } data - Parameters for sending data {@link string}. 3539 * @param { AsyncCallback<void> } callback - the callback of send. 3540 * @throws { BusinessError } 401 - Parameter error. 3541 * @throws { BusinessError } 2303501 - SSL is null. 3542 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3543 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3544 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3545 * @throws { BusinessError } 2300002 - System internal error. 3546 * @syscap SystemCapability.Communication.NetStack 3547 * @crossplatform 3548 * @since 10 3549 */ 3550 /** 3551 * Sends data over a TLSSocket connection. 3552 * @param { string | ArrayBuffer } data - Parameters for sending data. 3553 * @param { AsyncCallback<void> } callback - the callback of send. 3554 * @throws { BusinessError } 401 - Parameter error. 3555 * @throws { BusinessError } 2303501 - SSL is null. 3556 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3557 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3558 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3559 * @throws { BusinessError } 2300002 - System internal error. 3560 * @syscap SystemCapability.Communication.NetStack 3561 * @crossplatform 3562 * @since 12 3563 */ 3564 send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void; 3565 3566 /** 3567 * Sends data over a TLSSocket connection. 3568 * @param { string } data - Parameters for sending data {@link string}. 3569 * @returns { Promise<void> } The promise returned by the function. 3570 * @throws { BusinessError } 401 - Parameter error. 3571 * @throws { BusinessError } 2303501 - SSL is null. 3572 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3573 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3574 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3575 * @throws { BusinessError } 2300002 - System internal error. 3576 * @syscap SystemCapability.Communication.NetStack 3577 * @since 9 3578 */ 3579 /** 3580 * Sends data over a TLSSocket connection. 3581 * @param { string } data - Parameters for sending data {@link string}. 3582 * @returns { Promise<void> } The promise returned by the function. 3583 * @throws { BusinessError } 401 - Parameter error. 3584 * @throws { BusinessError } 2303501 - SSL is null. 3585 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3586 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3587 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3588 * @throws { BusinessError } 2300002 - System internal error. 3589 * @syscap SystemCapability.Communication.NetStack 3590 * @crossplatform 3591 * @since 10 3592 */ 3593 /** 3594 * Sends data over a TLSSocket connection. 3595 * @param { string | ArrayBuffer } data - Parameters for sending data. 3596 * @returns { Promise<void> } The promise returned by the function. 3597 * @throws { BusinessError } 401 - Parameter error. 3598 * @throws { BusinessError } 2303501 - SSL is null. 3599 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 3600 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3601 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3602 * @throws { BusinessError } 2300002 - System internal error. 3603 * @syscap SystemCapability.Communication.NetStack 3604 * @crossplatform 3605 * @since 12 3606 */ 3607 send(data: string | ArrayBuffer): Promise<void>; 3608 3609 /** 3610 * Closes a TLSSocket connection 3611 * @param { AsyncCallback<void> } callback - the callback of close. 3612 * @throws { BusinessError } 401 - Parameter error. 3613 * @throws { BusinessError } 2303501 - SSL is null. 3614 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3615 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3616 * @throws { BusinessError } 2300002 - System internal error. 3617 * @syscap SystemCapability.Communication.NetStack 3618 * @since 9 3619 */ 3620 /** 3621 * Closes a TLSSocket connection 3622 * @param { AsyncCallback<void> } callback - the callback of close. 3623 * @throws { BusinessError } 401 - Parameter error. 3624 * @throws { BusinessError } 2303501 - SSL is null. 3625 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3626 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3627 * @throws { BusinessError } 2300002 - System internal error. 3628 * @syscap SystemCapability.Communication.NetStack 3629 * @crossplatform 3630 * @since 10 3631 */ 3632 close(callback: AsyncCallback<void>): void; 3633 3634 /** 3635 * Closes a TLSSocket connection 3636 * @returns { Promise<void> } The promise returned by the function. 3637 * @throws { BusinessError } 401 - Parameter error. 3638 * @throws { BusinessError } 2303501 - SSL is null. 3639 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3640 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3641 * @throws { BusinessError } 2300002 - System internal error. 3642 * @syscap SystemCapability.Communication.NetStack 3643 * @since 9 3644 */ 3645 /** 3646 * Closes a TLSSocket connection 3647 * @returns { Promise<void> } The promise returned by the function. 3648 * @throws { BusinessError } 401 - Parameter error. 3649 * @throws { BusinessError } 2303501 - SSL is null. 3650 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 3651 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 3652 * @throws { BusinessError } 2300002 - System internal error. 3653 * @syscap SystemCapability.Communication.NetStack 3654 * @crossplatform 3655 * @since 10 3656 */ 3657 close(): Promise<void>; 3658 } 3659 3660 /** 3661 * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional. 3662 * @interface TLSSecureOptions 3663 * @syscap SystemCapability.Communication.NetStack 3664 * @since 9 3665 */ 3666 /** 3667 * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional. 3668 * @interface TLSSecureOptions 3669 * @syscap SystemCapability.Communication.NetStack 3670 * @crossplatform 3671 * @since 10 3672 */ 3673 export interface TLSSecureOptions { 3674 /** 3675 * Certificate used to verify the identity of the server 3676 * @type {string | Array<string>} 3677 * @syscap SystemCapability.Communication.NetStack 3678 * @since 9 3679 */ 3680 /** 3681 * Certificate used to verify the identity of the server. 3682 * @type {string | Array<string>} 3683 * @syscap SystemCapability.Communication.NetStack 3684 * @crossplatform 3685 * @since 10 3686 */ 3687 /** 3688 * Certificate used to verify the identity of the server, if it is not set, use system ca. 3689 * @type {?(string | Array<string>)} 3690 * @syscap SystemCapability.Communication.NetStack 3691 * @crossplatform 3692 * @since 12 3693 */ 3694 ca?: string | Array<string>; 3695 3696 /** 3697 * Certificate proving the identity of the client 3698 * @type {?string} 3699 * @syscap SystemCapability.Communication.NetStack 3700 * @since 9 3701 */ 3702 /** 3703 * Certificate proving the identity of the client 3704 * @type {?string} 3705 * @syscap SystemCapability.Communication.NetStack 3706 * @crossplatform 3707 * @since 10 3708 */ 3709 cert?: string; 3710 3711 /** 3712 * Private key of client certificate 3713 * @type {?string} 3714 * @syscap SystemCapability.Communication.NetStack 3715 * @since 9 3716 */ 3717 /** 3718 * Private key of client certificate 3719 * @type {?string} 3720 * @syscap SystemCapability.Communication.NetStack 3721 * @crossplatform 3722 * @since 10 3723 */ 3724 key?: string; 3725 3726 /** 3727 * Password of the private key 3728 * @type {?string} 3729 * @syscap SystemCapability.Communication.NetStack 3730 * @since 9 3731 */ 3732 /** 3733 * Password of the private key 3734 * @type {?string} 3735 * @syscap SystemCapability.Communication.NetStack 3736 * @crossplatform 3737 * @since 10 3738 */ 3739 password?: string; 3740 3741 /** 3742 * TLS protocol version 3743 * @type {?Protocol | Array<Protocol>} 3744 * @syscap SystemCapability.Communication.NetStack 3745 * @since 9 3746 */ 3747 /** 3748 * TLS protocol version 3749 * @type {?(Protocol | Array<Protocol>)} 3750 * @syscap SystemCapability.Communication.NetStack 3751 * @crossplatform 3752 * @since 10 3753 */ 3754 protocols?: Protocol | Array<Protocol>; 3755 3756 /** 3757 * default is false, use local cipher. 3758 * @type {?boolean} 3759 * @syscap SystemCapability.Communication.NetStack 3760 * @since 9 3761 */ 3762 /** 3763 * default is false, use local cipher. 3764 * @type {?boolean} 3765 * @syscap SystemCapability.Communication.NetStack 3766 * @crossplatform 3767 * @since 10 3768 */ 3769 useRemoteCipherPrefer?: boolean; 3770 3771 /** 3772 * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc), 3773 * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P> 3774 * @type {?string} 3775 * @syscap SystemCapability.Communication.NetStack 3776 * @since 9 3777 */ 3778 /** 3779 * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc), 3780 * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P> 3781 * @type {?string} 3782 * @syscap SystemCapability.Communication.NetStack 3783 * @crossplatform 3784 * @since 10 3785 */ 3786 signatureAlgorithms?: string; 3787 3788 /** 3789 * Crypto suite specification 3790 * @type {?string} 3791 * @syscap SystemCapability.Communication.NetStack 3792 * @since 9 3793 */ 3794 /** 3795 * Crypto suite specification 3796 * @type {?string} 3797 * @syscap SystemCapability.Communication.NetStack 3798 * @crossplatform 3799 * @since 10 3800 */ 3801 cipherSuite?: string; 3802 3803 /** 3804 * Used to set up bidirectional authentication. The default value is false. 3805 * @type {?boolean} 3806 * @syscap SystemCapability.Communication.NetStack 3807 * @since 12 3808 */ 3809 isBidirectionalAuthentication?: boolean; 3810 } 3811 3812 /** 3813 * Defines TLS connection options. 3814 * @interface TLSConnectOptions 3815 * @syscap SystemCapability.Communication.NetStack 3816 * @since 9 3817 */ 3818 /** 3819 * Defines TLS connection options. 3820 * @interface TLSConnectOptions 3821 * @syscap SystemCapability.Communication.NetStack 3822 * @crossplatform 3823 * @since 10 3824 */ 3825 export interface TLSConnectOptions { 3826 /** 3827 * Gateway address. 3828 * @type {NetAddress} 3829 * @syscap SystemCapability.Communication.NetStack 3830 * @since 9 3831 */ 3832 /** 3833 * Gateway address. 3834 * @type {NetAddress} 3835 * @syscap SystemCapability.Communication.NetStack 3836 * @crossplatform 3837 * @since 10 3838 */ 3839 address: NetAddress; 3840 3841 /** 3842 * Protocol http2TLS security related operations. 3843 * @type {TLSSecureOptions} 3844 * @syscap SystemCapability.Communication.NetStack 3845 * @since 9 3846 */ 3847 /** 3848 * Protocol http2TLS security related operations. 3849 * @type {TLSSecureOptions} 3850 * @syscap SystemCapability.Communication.NetStack 3851 * @crossplatform 3852 * @since 10 3853 */ 3854 secureOptions: TLSSecureOptions; 3855 3856 /** 3857 * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2" 3858 * @type {?Array<string>} 3859 * @syscap SystemCapability.Communication.NetStack 3860 * @since 9 3861 */ 3862 /** 3863 * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2" 3864 * @type {?Array<string>} 3865 * @syscap SystemCapability.Communication.NetStack 3866 * @crossplatform 3867 * @since 10 3868 */ 3869 ALPNProtocols?: Array<string>; 3870 3871 /** 3872 * Skip identity verification for remote servers. The default value is false. 3873 * @type {?boolean} 3874 * @syscap SystemCapability.Communication.NetStack 3875 * @since 12 3876 */ 3877 skipRemoteValidation?: boolean; 3878 3879 /** 3880 * Set this option for the proxy feature. 3881 * @type {?ProxyOptions} 3882 * @syscap SystemCapability.Communication.NetStack 3883 * @crossplatform 3884 * @since 18 3885 */ 3886 proxy?: ProxyOptions; 3887 } 3888 3889 /** 3890 * Enumerates TLS protocol versions. 3891 * @enum {string} 3892 * @syscap SystemCapability.Communication.NetStack 3893 * @since 9 3894 */ 3895 /** 3896 * Enumerates TLS protocol versions. 3897 * @enum {string} 3898 * @syscap SystemCapability.Communication.NetStack 3899 * @crossplatform 3900 * @since 10 3901 */ 3902 export enum Protocol { 3903 /** 3904 * Use TLSv1.2 protocol for communication. 3905 * @syscap SystemCapability.Communication.NetStack 3906 * @since 9 3907 */ 3908 /** 3909 * Use TLSv1.2 protocol for communication. 3910 * @syscap SystemCapability.Communication.NetStack 3911 * @crossplatform 3912 * @since 10 3913 */ 3914 TLSv12 = "TLSv1.2", 3915 3916 /** 3917 * Use TLSv1.3 protocol for communication. 3918 * @syscap SystemCapability.Communication.NetStack 3919 * @since 9 3920 */ 3921 /** 3922 * Use TLSv1.3 protocol for communication. 3923 * @syscap SystemCapability.Communication.NetStack 3924 * @crossplatform 3925 * @since 10 3926 */ 3927 TLSv13 = "TLSv1.3" 3928 } 3929 3930 /** 3931 * Defines the connection of the TCPSocket client and server. 3932 * @interface TCPSocketConnection 3933 * @syscap SystemCapability.Communication.NetStack 3934 * @since 10 3935 */ 3936 export interface TCPSocketConnection { 3937 /** 3938 * The id of a client connects to the TCPSocketServer. 3939 * @type {number} 3940 * @syscap SystemCapability.Communication.NetStack 3941 * @since 10 3942 */ 3943 clientId: number; 3944 3945 /** 3946 * Sends data over a TCPSocketServer connection to client. 3947 * @permission ohos.permission.INTERNET 3948 * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}. 3949 * @param { AsyncCallback<void> } callback - The callback of send. 3950 * @throws { BusinessError } 201 - Permission denied. 3951 * @throws { BusinessError } 401 - Parameter error. 3952 * @throws { BusinessError } 2300002 - System internal error. 3953 * @syscap SystemCapability.Communication.NetStack 3954 * @since 10 3955 */ 3956 send(options: TCPSendOptions, callback: AsyncCallback<void>): void; 3957 3958 /** 3959 * Sends data over a TCPSocketServer connection to client. 3960 * @permission ohos.permission.INTERNET 3961 * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}. 3962 * @returns { Promise<void> } The promise returned by the function. 3963 * @throws { BusinessError } 201 - Permission denied. 3964 * @throws { BusinessError } 401 - Parameter error. 3965 * @throws { BusinessError } 2300002 - System internal error. 3966 * @syscap SystemCapability.Communication.NetStack 3967 * @since 10 3968 */ 3969 send(options: TCPSendOptions): Promise<void>; 3970 3971 /** 3972 * Closes a TCPSocket client connection. 3973 * @permission ohos.permission.INTERNET 3974 * @param { AsyncCallback<void> } callback - The callback of close. 3975 * @throws { BusinessError } 201 - Permission denied. 3976 * @throws { BusinessError } 401 - Parameter error. 3977 * @throws { BusinessError } 2300002 - System internal error. 3978 * @syscap SystemCapability.Communication.NetStack 3979 * @since 10 3980 */ 3981 close(callback: AsyncCallback<void>): void; 3982 3983 /** 3984 * Closes a TCPSocket client connection. 3985 * @permission ohos.permission.INTERNET 3986 * @returns { Promise<void> } The promise returned by the function. 3987 * @throws { BusinessError } 201 - Permission denied. 3988 * @throws { BusinessError } 2300002 - System internal error. 3989 * @syscap SystemCapability.Communication.NetStack 3990 * @since 10 3991 */ 3992 close(): Promise<void>; 3993 3994 /** 3995 * Obtains the peer address of a TCPSocketServer connection. 3996 * @permission ohos.permission.INTERNET 3997 * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress. 3998 * @throws { BusinessError } 201 - Permission denied. 3999 * @throws { BusinessError } 401 - Parameter error. 4000 * @throws { BusinessError } 2300002 - System internal error. 4001 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4002 * @syscap SystemCapability.Communication.NetStack 4003 * @since 10 4004 */ 4005 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 4006 4007 /** 4008 * Obtains the peer address of a TCPSocketServer connection. 4009 * @permission ohos.permission.INTERNET 4010 * @returns { Promise<NetAddress> } The promise returned by the function. 4011 * @throws { BusinessError } 201 - Permission denied. 4012 * @throws { BusinessError } 2300002 - System internal error. 4013 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4014 * @syscap SystemCapability.Communication.NetStack 4015 * @since 10 4016 */ 4017 getRemoteAddress(): Promise<NetAddress>; 4018 4019 /** 4020 * Obtains the local address of a TCPSocketServer connection. 4021 * @returns { Promise<NetAddress> } The promise returned by the function. 4022 * @throws { BusinessError } 2300002 - System internal error. 4023 * @throws { BusinessError } 2301009 - Bad file descriptor. 4024 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4025 * @syscap SystemCapability.Communication.NetStack 4026 * @since 12 4027 */ 4028 getLocalAddress(): Promise<NetAddress>; 4029 4030 /** 4031 * Listens for message receiving events of the TCPSocketConnection. 4032 * @param { 'message' } type - Indicates Event name. 4033 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on. 4034 * @throws { BusinessError } 401 - Parameter error. 4035 * @syscap SystemCapability.Communication.NetStack 4036 * @since 10 4037 */ 4038 /** 4039 * Listens for message receiving events of the TCPSocketConnection. 4040 * @param { 'message' } type - Indicates Event name. 4041 * @param { Callback<SocketMessageInfo> } callback - The callback of on. 4042 * @throws { BusinessError } 401 - Parameter error. 4043 * @syscap SystemCapability.Communication.NetStack 4044 * @since 11 4045 */ 4046 /** 4047 * Listens for message receiving events of the TCPSocketConnection. 4048 * @param { 'message' } type - Indicates Event name. 4049 * @param { Callback<SocketMessageInfo> } callback - The callback of on. 4050 * @throws { BusinessError } 401 - Parameter error. 4051 * @syscap SystemCapability.Communication.NetStack 4052 * @crossplatform 4053 * @since 12 4054 */ 4055 on(type: 'message', callback: Callback<SocketMessageInfo>): void; 4056 4057 /** 4058 * Cancels listening for message receiving events of the TCPSocketConnection. 4059 * @param { 'message' } type - Indicates Event name. 4060 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off. 4061 * @throws { BusinessError } 401 - Parameter error. 4062 * @syscap SystemCapability.Communication.NetStack 4063 * @since 10 4064 */ 4065 /** 4066 * Cancels listening for message receiving events of the TCPSocketConnection. 4067 * @param { 'message' } type - Indicates Event name. 4068 * @param { Callback<SocketMessageInfo> } callback - The callback of off. 4069 * @throws { BusinessError } 401 - Parameter error. 4070 * @syscap SystemCapability.Communication.NetStack 4071 * @since 11 4072 */ 4073 /** 4074 * Cancels listening for message receiving events of the TCPSocketConnection. 4075 * @param { 'message' } type - Indicates Event name. 4076 * @param { Callback<SocketMessageInfo> } callback - The callback of off. 4077 * @throws { BusinessError } 401 - Parameter error. 4078 * @syscap SystemCapability.Communication.NetStack 4079 * @crossplatform 4080 * @since 12 4081 */ 4082 off(type: 'message', callback?: Callback<SocketMessageInfo>): void; 4083 4084 /** 4085 * Listens for close events of the TCPSocketConnection. 4086 * @param { 'close' } type - Indicates Event name. 4087 * @param { Callback<void> } callback - The callback of on. 4088 * @throws { BusinessError } 401 - Parameter error. 4089 * @syscap SystemCapability.Communication.NetStack 4090 * @since 10 4091 */ 4092 on(type: 'close', callback: Callback<void>): void; 4093 4094 /** 4095 * Cancels listening for close events of the TCPSocketConnection. 4096 * @param { 'close' } type - Indicates Event name. 4097 * @param { Callback<void> } callback - The callback of off. 4098 * @throws { BusinessError } 401 - Parameter error. 4099 * @syscap SystemCapability.Communication.NetStack 4100 * @since 10 4101 */ 4102 off(type: 'close', callback?: Callback<void>): void; 4103 4104 /** 4105 * Listens for error events of the TCPSocketConnection. 4106 * @param { 'error' } type - Indicates Event name. 4107 * @param { ErrorCallback } callback - The callback of on. 4108 * @throws { BusinessError } 401 - Parameter error. 4109 * @syscap SystemCapability.Communication.NetStack 4110 * @since 10 4111 */ 4112 on(type: 'error', callback: ErrorCallback): void; 4113 4114 /** 4115 * Cancels listening for error events of the TCPSocketConnection. 4116 * @param { 'error' } type - Indicates Event name. 4117 * @param { ErrorCallback } callback - The callback of off. 4118 * @throws { BusinessError } 401 - Parameter error. 4119 * @syscap SystemCapability.Communication.NetStack 4120 * @since 10 4121 */ 4122 off(type: 'error', callback?: ErrorCallback): void; 4123 } 4124 4125 /** 4126 * Defines a TCPSocket server connection. 4127 * @interface TCPSocketServer 4128 * @syscap SystemCapability.Communication.NetStack 4129 * @since 10 4130 */ 4131 export interface TCPSocketServer { 4132 /** 4133 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 4134 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 4135 * for accept processing and uses poll multiplex to process client connections.</p> 4136 * @permission ohos.permission.INTERNET 4137 * @param { NetAddress } address - Network address information {@link NetAddress}. 4138 * @param { AsyncCallback<void> } callback - The callback of listen. 4139 * @throws { BusinessError } 401 - Parameter error. 4140 * @throws { BusinessError } 201 - Permission denied. 4141 * @throws { BusinessError } 2300002 - System internal error. 4142 * @throws { BusinessError } 2303109 - Bad file number. 4143 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 4144 * @throws { BusinessError } 2303198 - Address already in use. 4145 * @throws { BusinessError } 2303199 - Cannot assign requested address. 4146 * @syscap SystemCapability.Communication.NetStack 4147 * @since 10 4148 */ 4149 listen(address: NetAddress, callback: AsyncCallback<void>): void; 4150 4151 /** 4152 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 4153 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 4154 * for accept processing and uses poll multiplex to process client connections.</p> 4155 * @permission ohos.permission.INTERNET 4156 * @param { NetAddress } address - Network address information {@link NetAddress}. 4157 * @returns { Promise<void> } The promise returned by the function. 4158 * @throws { BusinessError } 401 - Parameter error. 4159 * @throws { BusinessError } 201 - Permission denied. 4160 * @throws { BusinessError } 2300002 - System internal error. 4161 * @throws { BusinessError } 2303109 - Bad file number. 4162 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 4163 * @throws { BusinessError } 2303198 - Address already in use. 4164 * @throws { BusinessError } 2303199 - Cannot assign requested address. 4165 * @syscap SystemCapability.Communication.NetStack 4166 * @since 10 4167 */ 4168 listen(address: NetAddress): Promise<void>; 4169 4170 /** 4171 * Obtains the status of the TCPSocketServer connection. 4172 * @permission ohos.permission.INTERNET 4173 * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState. 4174 * @throws { BusinessError } 201 - Permission denied. 4175 * @throws { BusinessError } 401 - Parameter error. 4176 * @throws { BusinessError } 2300002 - System internal error. 4177 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4178 * @syscap SystemCapability.Communication.NetStack 4179 * @since 10 4180 */ 4181 getState(callback: AsyncCallback<SocketStateBase>): void; 4182 4183 /** 4184 * Obtains the status of the TCPSocketServer connection. 4185 * @permission ohos.permission.INTERNET 4186 * @returns { Promise<SocketStateBase> } The promise returned by the function. 4187 * @throws { BusinessError } 201 - Permission denied. 4188 * @throws { BusinessError } 2300002 - System internal error. 4189 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4190 * @syscap SystemCapability.Communication.NetStack 4191 * @since 10 4192 */ 4193 getState(): Promise<SocketStateBase>; 4194 4195 /** 4196 * Sets other attributes of the TCPSocketServer connection. 4197 * @permission ohos.permission.INTERNET 4198 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 4199 * @param { AsyncCallback<void> } callback - The callback of setExtraOptions. 4200 * @throws { BusinessError } 201 - Permission denied. 4201 * @throws { BusinessError } 401 - Parameter error. 4202 * @throws { BusinessError } 2300002 - System internal error. 4203 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4204 * @syscap SystemCapability.Communication.NetStack 4205 * @since 10 4206 */ 4207 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 4208 4209 /** 4210 * Sets other attributes of the TCPSocketServer connection. 4211 * @permission ohos.permission.INTERNET 4212 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 4213 * @returns { Promise<void> } The promise returned by the function. 4214 * @throws { BusinessError } 201 - Permission denied. 4215 * @throws { BusinessError } 401 - Parameter error. 4216 * @throws { BusinessError } 2300002 - System internal error. 4217 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4218 * @syscap SystemCapability.Communication.NetStack 4219 * @since 10 4220 */ 4221 setExtraOptions(options: TCPExtraOptions): Promise<void>; 4222 4223 /** 4224 * Obtains the local address of a TCPSocketServer connection. 4225 * @returns { Promise<NetAddress> } The promise returned by the function. 4226 * @throws { BusinessError } 2300002 - System internal error. 4227 * @throws { BusinessError } 2301009 - Bad file descriptor. 4228 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4229 * @syscap SystemCapability.Communication.NetStack 4230 * @since 12 4231 */ 4232 getLocalAddress(): Promise<NetAddress>; 4233 4234 /** 4235 * Listens for connect events of the TCPSocketServer connection. 4236 * @param { 'connect' } type - Indicates Event name. 4237 * @param { Callback<TCPSocketConnection> } callback - The callback of on. 4238 * @throws { BusinessError } 401 - Parameter error. 4239 * @syscap SystemCapability.Communication.NetStack 4240 * @since 10 4241 */ 4242 on(type: 'connect', callback: Callback<TCPSocketConnection>): void; 4243 4244 /** 4245 * Cancels listening for connect events of the TCPSocketServer connection. 4246 * @param { 'connect' } type - Indicates Event name. 4247 * @param { Callback<TCPSocketConnection> } callback - The callback of off. 4248 * @throws { BusinessError } 401 - Parameter error. 4249 * @syscap SystemCapability.Communication.NetStack 4250 * @since 10 4251 */ 4252 off(type: 'connect', callback?: Callback<TCPSocketConnection>): void; 4253 4254 /** 4255 * Listens for error events of the TCPSocketServer connection. 4256 * @param { 'error' } type - Indicates Event name. 4257 * @param { ErrorCallback } callback - The callback of on. 4258 * @throws { BusinessError } 401 - Parameter error. 4259 * @syscap SystemCapability.Communication.NetStack 4260 * @since 10 4261 */ 4262 on(type: 'error', callback: ErrorCallback): void; 4263 4264 /** 4265 * Cancels listening for error events of the TCPSocketServer connection. 4266 * @param { 'error' } type - Indicates Event name. 4267 * @param { ErrorCallback } callback - The callback of off. 4268 * @throws { BusinessError } 401 - Parameter error. 4269 * @syscap SystemCapability.Communication.NetStack 4270 * @since 10 4271 */ 4272 off(type: 'error', callback?: ErrorCallback): void; 4273 } 4274 4275 /** 4276 * Defines the connection of the TLSSocket client and server. 4277 * @interface TLSSocketConnection 4278 * @syscap SystemCapability.Communication.NetStack 4279 * @since 10 4280 */ 4281 export interface TLSSocketConnection { 4282 /** 4283 * The id of a client connects to the TLSSocketServer. 4284 * @type {number} 4285 * @syscap SystemCapability.Communication.NetStack 4286 * @since 10 4287 */ 4288 clientId: number; 4289 4290 /** 4291 * Sends data over a TLSSocketServer connection to client. 4292 * @param { string } data - Parameters for sending data. 4293 * @param { AsyncCallback<void> } callback - The callback of send. 4294 * @throws { BusinessError } 401 - Parameter error. 4295 * @throws { BusinessError } 2303501 - SSL is null. 4296 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4297 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4298 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4299 * @throws { BusinessError } 2300002 - System internal error. 4300 * @syscap SystemCapability.Communication.NetStack 4301 * @since 10 4302 */ 4303 /** 4304 * Sends data over a TLSSocketServer connection to client. 4305 * @param { string | ArrayBuffer } data - Parameters for sending data. 4306 * @param { AsyncCallback<void> } callback - The callback of send. 4307 * @throws { BusinessError } 401 - Parameter error. 4308 * @throws { BusinessError } 2303501 - SSL is null. 4309 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4310 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4311 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4312 * @throws { BusinessError } 2300002 - System internal error. 4313 * @syscap SystemCapability.Communication.NetStack 4314 * @since 12 4315 */ 4316 send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void; 4317 4318 /** 4319 * Sends data over a TLSSocketServer connection to client. 4320 * @param { string } data - Parameters for sending data. 4321 * @returns { Promise<void> } The promise returned by the function. 4322 * @throws { BusinessError } 401 - Parameter error. 4323 * @throws { BusinessError } 2303501 - SSL is null. 4324 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4325 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4326 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4327 * @throws { BusinessError } 2300002 - System internal error. 4328 * @syscap SystemCapability.Communication.NetStack 4329 * @since 10 4330 */ 4331 /** 4332 * Sends data over a TLSSocketServer connection to client. 4333 * @param { string | ArrayBuffer } data - Parameters for sending data. 4334 * @returns { Promise<void> } The promise returned by the function. 4335 * @throws { BusinessError } 401 - Parameter error. 4336 * @throws { BusinessError } 2303501 - SSL is null. 4337 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4338 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4339 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4340 * @throws { BusinessError } 2300002 - System internal error. 4341 * @syscap SystemCapability.Communication.NetStack 4342 * @since 12 4343 */ 4344 send(data: string | ArrayBuffer): Promise<void>; 4345 4346 /** 4347 * Closes a TLSSocket client connection. 4348 * @param { AsyncCallback<void> } callback - The callback of close. 4349 * @throws { BusinessError } 401 - Parameter error. 4350 * @throws { BusinessError } 2303501 - SSL is null. 4351 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4352 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4353 * @throws { BusinessError } 2300002 - System internal error. 4354 * @syscap SystemCapability.Communication.NetStack 4355 * @since 10 4356 */ 4357 close(callback: AsyncCallback<void>): void; 4358 4359 /** 4360 * Closes a TLSSocket client connection. 4361 * @returns { Promise<void> } The promise returned by the function. 4362 * @throws { BusinessError } 2303501 - SSL is null. 4363 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4364 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4365 * @throws { BusinessError } 2300002 - System internal error. 4366 * @syscap SystemCapability.Communication.NetStack 4367 * @since 10 4368 */ 4369 close(): Promise<void>; 4370 4371 /** 4372 * Obtains the peer address of a TLSSocketServer connection. 4373 * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress. 4374 * @throws { BusinessError } 401 - Parameter error. 4375 * @throws { BusinessError } 2300002 - System internal error. 4376 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4377 * @syscap SystemCapability.Communication.NetStack 4378 * @since 10 4379 */ 4380 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 4381 4382 /** 4383 * Obtains the peer address of a TLSSocketServer connection. 4384 * @returns { Promise<NetAddress> } The promise returned by the function. 4385 * @throws { BusinessError } 2300002 - System internal error. 4386 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4387 * @syscap SystemCapability.Communication.NetStack 4388 * @since 10 4389 */ 4390 getRemoteAddress(): Promise<NetAddress>; 4391 4392 /** 4393 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 4394 * an empty object will be returned. If the socket is destroyed, null is returned.</p> 4395 * It only contains the peer's certificate. 4396 * @param { AsyncCallback<X509CertRawData> } callback - The callback of getRemoteCertificate. 4397 * @throws { BusinessError } 401 - Parameter error. 4398 * @throws { BusinessError } 2303501 - SSL is null. 4399 * @throws { BusinessError } 2300002 - System internal error. 4400 * @syscap SystemCapability.Communication.NetStack 4401 * @since 10 4402 */ 4403 getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void; 4404 4405 /** 4406 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 4407 * an empty object will be returned. If the socket is destroyed, null is returned.</p> 4408 * It only contains the peer's certificate. 4409 * @returns { Promise<X509CertRawData> } The promise returned by the function. 4410 * @throws { BusinessError } 2303501 - SSL is null. 4411 * @throws { BusinessError } 2300002 - System internal error. 4412 * @syscap SystemCapability.Communication.NetStack 4413 * @since 10 4414 */ 4415 getRemoteCertificate(): Promise<X509CertRawData>; 4416 4417 /** 4418 * Returns a list containing the negotiated cipher suite information. 4419 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 4420 * @param { AsyncCallback<Array<string>> } callback - The callback of getCipherSuite. 4421 * @throws { BusinessError } 401 - Parameter error. 4422 * @throws { BusinessError } 2303501 - SSL is null. 4423 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 4424 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4425 * @throws { BusinessError } 2300002 - System internal error. 4426 * @syscap SystemCapability.Communication.NetStack 4427 * @since 10 4428 */ 4429 getCipherSuite(callback: AsyncCallback<Array<string>>): void; 4430 4431 /** 4432 * Returns a list containing the negotiated cipher suite information. 4433 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 4434 * @returns { Promise<Array<string>> } The promise returned by the function. 4435 * @throws { BusinessError } 2303501 - SSL is null. 4436 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 4437 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4438 * @throws { BusinessError } 2300002 - System internal error. 4439 * @syscap SystemCapability.Communication.NetStack 4440 * @since 10 4441 */ 4442 getCipherSuite(): Promise<Array<string>>; 4443 4444 /** 4445 * <p>The list of signature algorithms shared between the server and the client, 4446 * in descending order of priority.</p> 4447 * @param { AsyncCallback<Array<string>> } callback - The callback of getSignatureAlgorithms. 4448 * @throws { BusinessError } 401 - Parameter error. 4449 * @throws { BusinessError } 2303501 - SSL is null. 4450 * @throws { BusinessError } 2300002 - System internal error. 4451 * @syscap SystemCapability.Communication.NetStack 4452 * @since 10 4453 */ 4454 getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void; 4455 4456 /** 4457 * <p>The list of signature algorithms shared between the server and the client, 4458 * in descending order of priority.</p> 4459 * @returns { Promise<Array<string>> } The promise returned by the function. 4460 * @throws { BusinessError } 2303501 - SSL is null. 4461 * @throws { BusinessError } 2300002 - System internal error. 4462 * @syscap SystemCapability.Communication.NetStack 4463 * @since 10 4464 */ 4465 getSignatureAlgorithms(): Promise<Array<string>>; 4466 4467 /** 4468 * Obtains the local address of a TLSSocketServer connection. 4469 * @returns { Promise<NetAddress> } The promise returned by the function. 4470 * @throws { BusinessError } 2300002 - System internal error. 4471 * @throws { BusinessError } 2301009 - Bad file descriptor. 4472 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4473 * @syscap SystemCapability.Communication.NetStack 4474 * @since 12 4475 */ 4476 getLocalAddress(): Promise<NetAddress>; 4477 4478 /** 4479 * Listens for message receiving events of the TLSSocketConnection. 4480 * @param { 'message' } type - Indicates Event name. 4481 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on. 4482 * @throws { BusinessError } 401 - Parameter error. 4483 * @syscap SystemCapability.Communication.NetStack 4484 * @since 10 4485 */ 4486 /** 4487 * Listens for message receiving events of the TLSSocketConnection. 4488 * @param { 'message' } type - Indicates Event name. 4489 * @param { Callback<SocketMessageInfo> } callback - The callback of on. 4490 * @throws { BusinessError } 401 - Parameter error. 4491 * @syscap SystemCapability.Communication.NetStack 4492 * @since 11 4493 */ 4494 /** 4495 * Listens for message receiving events of the TLSSocketConnection. 4496 * @param { 'message' } type - Indicates Event name. 4497 * @param { Callback<SocketMessageInfo> } callback - The callback of on. 4498 * @throws { BusinessError } 401 - Parameter error. 4499 * @syscap SystemCapability.Communication.NetStack 4500 * @crossplatform 4501 * @since 12 4502 */ 4503 on(type: 'message', callback: Callback<SocketMessageInfo>): void; 4504 4505 /** 4506 * Cancels listening for message receiving events of the TLSSocketConnection. 4507 * @param { 'message' } type - Indicates Event name. 4508 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off. 4509 * @throws { BusinessError } 401 - Parameter error. 4510 * @syscap SystemCapability.Communication.NetStack 4511 * @since 10 4512 */ 4513 /** 4514 * Cancels listening for message receiving events of the TLSSocketConnection. 4515 * @param { 'message' } type - Indicates Event name. 4516 * @param { Callback<SocketMessageInfo> } callback - The callback of off. 4517 * @throws { BusinessError } 401 - Parameter error. 4518 * @syscap SystemCapability.Communication.NetStack 4519 * @since 11 4520 */ 4521 /** 4522 * Cancels listening for message receiving events of the TLSSocketConnection. 4523 * @param { 'message' } type - Indicates Event name. 4524 * @param { Callback<SocketMessageInfo> } callback - The callback of off. 4525 * @throws { BusinessError } 401 - Parameter error. 4526 * @syscap SystemCapability.Communication.NetStack 4527 * @crossplatform 4528 * @since 12 4529 */ 4530 off(type: 'message', callback?: Callback<SocketMessageInfo>): void; 4531 4532 /** 4533 * Listens for close events of the TLSSocketConnection. 4534 * @param { 'close' } type - Indicates Event name. 4535 * @param { Callback<void> } callback - The callback of on. 4536 * @throws { BusinessError } 401 - Parameter error. 4537 * @syscap SystemCapability.Communication.NetStack 4538 * @since 10 4539 */ 4540 on(type: 'close', callback: Callback<void>): void; 4541 4542 /** 4543 * Cancels listening for close events of the TLSSocketConnection. 4544 * @param { 'close' } type - Indicates Event name. 4545 * @param { Callback<void> } callback - The callback of off. 4546 * @throws { BusinessError } 401 - Parameter error. 4547 * @syscap SystemCapability.Communication.NetStack 4548 * @since 10 4549 */ 4550 off(type: 'close', callback?: Callback<void>): void; 4551 4552 /** 4553 * Listens for error events of the TLSSocketConnection. 4554 * @param { 'error' } type - Indicates Event name. 4555 * @param { ErrorCallback } callback - The callback of on. 4556 * @throws { BusinessError } 401 - Parameter error. 4557 * @syscap SystemCapability.Communication.NetStack 4558 * @since 10 4559 */ 4560 on(type: 'error', callback: ErrorCallback): void; 4561 4562 /** 4563 * Cancels listening for error events of the TLSSocketConnection. 4564 * @param { 'error' } type - Indicates Event name. 4565 * @param { ErrorCallback } callback - The callback of off. 4566 * @throws { BusinessError } 401 - Parameter error. 4567 * @syscap SystemCapability.Communication.NetStack 4568 * @since 10 4569 */ 4570 off(type: 'error', callback?: ErrorCallback): void; 4571 } 4572 4573 /** 4574 * Defines the socket connection information. 4575 * @interface SocketMessageInfo 4576 * @syscap SystemCapability.Communication.NetStack 4577 * @crossplatform 4578 * @since 11 4579 */ 4580 export interface SocketMessageInfo { 4581 /** 4582 * Receive the message event. 4583 * @type { ArrayBuffer } 4584 * @syscap SystemCapability.Communication.NetStack 4585 * @crossplatform 4586 * @since 11 4587 */ 4588 message: ArrayBuffer; 4589 /** 4590 * Socket connection information. 4591 * @type { SocketRemoteInfo } 4592 * @syscap SystemCapability.Communication.NetStack 4593 * @crossplatform 4594 * @since 11 4595 */ 4596 remoteInfo: SocketRemoteInfo; 4597 } 4598 4599 /** 4600 * Defines a TLSSocketServer server connection. 4601 * @interface TLSSocketServer 4602 * @syscap SystemCapability.Communication.NetStack 4603 * @since 10 4604 */ 4605 export interface TLSSocketServer { 4606 /** 4607 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 4608 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 4609 * for accept processing and uses poll multiplex to process client connections.</p> 4610 * @permission ohos.permission.INTERNET 4611 * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}. 4612 * @param { AsyncCallback<void> } callback - The callback of listen. 4613 * @throws { BusinessError } 401 - Parameter error. 4614 * @throws { BusinessError } 201 - Permission denied. 4615 * @throws { BusinessError } 2300002 - System internal error. 4616 * @throws { BusinessError } 2303109 - Bad file number. 4617 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 4618 * @throws { BusinessError } 2303198 - Address already in use. 4619 * @throws { BusinessError } 2303199 - Cannot assign requested address. 4620 * @throws { BusinessError } 2303501 - SSL is null. 4621 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 4622 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4623 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4624 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4625 * @syscap SystemCapability.Communication.NetStack 4626 * @since 10 4627 */ 4628 listen(options: TLSConnectOptions, callback: AsyncCallback<void>): void; 4629 4630 /** 4631 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 4632 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 4633 * for accept processing and uses poll multiplex to process client connections.</p> 4634 * @permission ohos.permission.INTERNET 4635 * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}. 4636 * @returns { Promise<void> } The promise returned by the function. 4637 * @throws { BusinessError } 401 - Parameter error. 4638 * @throws { BusinessError } 201 - Permission denied. 4639 * @throws { BusinessError } 2300002 - System internal error. 4640 * @throws { BusinessError } 2303109 - Bad file number. 4641 * @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again. 4642 * @throws { BusinessError } 2303198 - Address already in use. 4643 * @throws { BusinessError } 2303199 - Cannot assign requested address. 4644 * @throws { BusinessError } 2303501 - SSL is null. 4645 * @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket. 4646 * @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket. 4647 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4648 * @throws { BusinessError } 2303506 - Failed to close the TLS connection. 4649 * @syscap SystemCapability.Communication.NetStack 4650 * @since 10 4651 */ 4652 listen(options: TLSConnectOptions): Promise<void>; 4653 4654 /** 4655 * Obtains the status of the TLSSocketServer connection. 4656 * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState. 4657 * @throws { BusinessError } 401 - Parameter error. 4658 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4659 * @throws { BusinessError } 2300002 - System internal error. 4660 * @syscap SystemCapability.Communication.NetStack 4661 * @since 10 4662 */ 4663 getState(callback: AsyncCallback<SocketStateBase>): void; 4664 4665 /** 4666 * Obtains the status of the TLSSocketServer connection. 4667 * @returns { Promise<SocketStateBase> } The promise returned by the function. 4668 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4669 * @throws { BusinessError } 2300002 - System internal error. 4670 * @syscap SystemCapability.Communication.NetStack 4671 * @since 10 4672 */ 4673 getState(): Promise<SocketStateBase>; 4674 4675 /** 4676 * Sets other attributes of the TLSSocketServer connection. 4677 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 4678 * @param { AsyncCallback<void> } callback - The callback of setExtraOptions. 4679 * @throws { BusinessError } 401 - Parameter error. 4680 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4681 * @throws { BusinessError } 2300002 - System internal error. 4682 * @syscap SystemCapability.Communication.NetStack 4683 * @since 10 4684 */ 4685 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 4686 4687 /** 4688 * Sets other attributes of the TLSSocketServer connection. 4689 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 4690 * @returns { Promise<void> } The promise returned by the function. 4691 * @throws { BusinessError } 401 - Parameter error. 4692 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4693 * @throws { BusinessError } 2300002 - System internal error. 4694 * @syscap SystemCapability.Communication.NetStack 4695 * @since 10 4696 */ 4697 setExtraOptions(options: TCPExtraOptions): Promise<void>; 4698 4699 /** 4700 * Returns an object representing a local certificate. 4701 * @param { AsyncCallback<X509CertRawData> } callback - The callback of getCertificate. 4702 * @throws { BusinessError } 401 - Parameter error. 4703 * @throws { BusinessError } 2303501 - SSL is null. 4704 * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate. 4705 * @throws { BusinessError } 2300002 - System internal error. 4706 * @syscap SystemCapability.Communication.NetStack 4707 * @since 10 4708 */ 4709 getCertificate(callback: AsyncCallback<X509CertRawData>): void; 4710 4711 /** 4712 * Returns an object representing a local certificate. 4713 * @returns { Promise<X509CertRawData> } The promise returned by the function. 4714 * @throws { BusinessError } 2303501 - SSL is null. 4715 * @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate. 4716 * @throws { BusinessError } 2300002 - System internal error. 4717 * @syscap SystemCapability.Communication.NetStack 4718 * @since 10 4719 */ 4720 getCertificate(): Promise<X509CertRawData>; 4721 4722 /** 4723 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 4724 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 4725 * Server sockets or disconnected client sockets will return a value of null. 4726 * @param { AsyncCallback<string> } callback - The callback of getProtocol. 4727 * @throws { BusinessError } 401 - Parameter error. 4728 * @throws { BusinessError } 2303501 - SSL is null. 4729 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4730 * @throws { BusinessError } 2300002 - System internal error. 4731 * @syscap SystemCapability.Communication.NetStack 4732 * @since 10 4733 */ 4734 getProtocol(callback: AsyncCallback<string>): void; 4735 4736 /** 4737 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 4738 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 4739 * Server sockets or disconnected client sockets will return a value of null. 4740 * @returns { Promise<string> } The promise returned by the function. 4741 * @throws { BusinessError } 2303501 - SSL is null. 4742 * @throws { BusinessError } 2303505 - An error occurred in the TLS system call. 4743 * @throws { BusinessError } 2300002 - System internal error. 4744 * @syscap SystemCapability.Communication.NetStack 4745 * @since 10 4746 */ 4747 getProtocol(): Promise<string>; 4748 4749 /** 4750 * Obtains the local address of the TLSSocketServer connection. 4751 * @returns { Promise<NetAddress> } The promise returned by the function. 4752 * @throws { BusinessError } 2300002 - System internal error. 4753 * @throws { BusinessError } 2301009 - Bad file descriptor. 4754 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 4755 * @syscap SystemCapability.Communication.NetStack 4756 * @since 12 4757 */ 4758 getLocalAddress(): Promise<NetAddress>; 4759 4760 /** 4761 * Listens for connect events of the TLSSocketServer connection. 4762 * @param { 'connect' } type - Indicates Event name. 4763 * @param { Callback<TLSSocketConnection> } callback - The callback of on. 4764 * @throws { BusinessError } 401 - Parameter error. 4765 * @syscap SystemCapability.Communication.NetStack 4766 * @since 10 4767 */ 4768 on(type: 'connect', callback: Callback<TLSSocketConnection>): void; 4769 4770 /** 4771 * Cancels listening for connect events of the TLSSocketServer connection. 4772 * @param { 'connect' } type - Indicates Event name. 4773 * @param { Callback<TLSSocketConnection> } callback - The callback of off. 4774 * @throws { BusinessError } 401 - Parameter error. 4775 * @syscap SystemCapability.Communication.NetStack 4776 * @since 10 4777 */ 4778 off(type: 'connect', callback?: Callback<TLSSocketConnection>): void; 4779 4780 /** 4781 * Listens for error events of the TLSSocketServer connection. 4782 * @param { 'error' } type - Indicates Event name. 4783 * @param { ErrorCallback } callback - The callback of on. 4784 * @throws { BusinessError } 401 - Parameter error. 4785 * @syscap SystemCapability.Communication.NetStack 4786 * @since 10 4787 */ 4788 on(type: 'error', callback: ErrorCallback): void; 4789 4790 /** 4791 * Cancels listening for error events of the TLSSocketServer connection. 4792 * @param { 'error' } type - Indicates Event name. 4793 * @param { ErrorCallback } callback - The callback of off. 4794 * @throws { BusinessError } 401 - Parameter error. 4795 * @syscap SystemCapability.Communication.NetStack 4796 * @since 10 4797 */ 4798 off(type: 'error', callback?: ErrorCallback): void; 4799 } 4800} 4801 4802export default socket; 4803