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 Network Kit 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 * @syscap SystemCapability.Communication.NetStack 48 * @crossplatform 49 * @since 10 50 */ 51 export type X509CertRawData = cert.EncodingBlob; 52 53 /** 54 * Creates a UDPSocket object. 55 * @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance. 56 * @syscap SystemCapability.Communication.NetStack 57 * @since 7 58 */ 59 /** 60 * Creates a UDPSocket object. 61 * @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance. 62 * @syscap SystemCapability.Communication.NetStack 63 * @crossplatform 64 * @since 10 65 */ 66 function constructUDPSocketInstance(): UDPSocket; 67 68 /** 69 * Creates a MulticastSocket object. 70 * @returns { MulticastSocket } the MulticastSocket of the constructMulticastSocketInstance. 71 * @syscap SystemCapability.Communication.NetStack 72 * @since 11 73 */ 74 function constructMulticastSocketInstance(): MulticastSocket; 75 76 /** 77 * Creates a TCPSocket object. 78 * @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance. 79 * @syscap SystemCapability.Communication.NetStack 80 * @since 7 81 */ 82 /** 83 * Creates a TCPSocket object. 84 * @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance. 85 * @syscap SystemCapability.Communication.NetStack 86 * @crossplatform 87 * @since 10 88 */ 89 function constructTCPSocketInstance(): TCPSocket; 90 91 /** 92 * Creates a TLSSocket object. 93 * @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance. 94 * @syscap SystemCapability.Communication.NetStack 95 * @since 9 96 */ 97 /** 98 * Creates a TLSSocket object. 99 * @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance. 100 * @syscap SystemCapability.Communication.NetStack 101 * @crossplatform 102 * @since 10 103 */ 104 function constructTLSSocketInstance(): TLSSocket; 105 106 /** 107 * Creates a TCPSocketServer object. 108 * @returns { TCPSocketServer } the TCPSocketServer of the constructTCPSocketServerInstance. 109 * @syscap SystemCapability.Communication.NetStack 110 * @since 10 111 */ 112 function constructTCPSocketServerInstance(): TCPSocketServer; 113 114 /** 115 * Creates a TLSSocketServer object. 116 * @returns { TLSSocketServer } the TLSSocketServer of the constructTLSSocketServerInstance. 117 * @syscap SystemCapability.Communication.NetStack 118 * @since 10 119 */ 120 function constructTLSSocketServerInstance(): TLSSocketServer; 121 122 /** 123 * Defines the parameters for sending data over the UDPSocket connection. 124 * @interface UDPSendOptions 125 * @syscap SystemCapability.Communication.NetStack 126 * @since 7 127 */ 128 /** 129 * Defines the parameters for sending data over the UDPSocket connection. 130 * @interface UDPSendOptions 131 * @syscap SystemCapability.Communication.NetStack 132 * @crossplatform 133 * @since 10 134 */ 135 export interface UDPSendOptions { 136 /** 137 * Data to send. 138 * @type {string | ArrayBuffer} 139 * @syscap SystemCapability.Communication.NetStack 140 * @since 7 141 */ 142 /** 143 * Data to send. 144 * @type {string | ArrayBuffer} 145 * @syscap SystemCapability.Communication.NetStack 146 * @crossplatform 147 * @since 10 148 */ 149 data: string | ArrayBuffer; 150 151 /** 152 * Destination address. 153 * @type {NetAddress} 154 * @syscap SystemCapability.Communication.NetStack 155 * @since 7 156 */ 157 /** 158 * Destination address. 159 * @type {NetAddress} 160 * @syscap SystemCapability.Communication.NetStack 161 * @crossplatform 162 * @since 10 163 */ 164 address: NetAddress; 165 } 166 167 /** 168 * @interface ExtraOptionsBase 169 * @syscap SystemCapability.Communication.NetStack 170 * @since 7 171 */ 172 /** 173 * @interface ExtraOptionsBase 174 * @syscap SystemCapability.Communication.NetStack 175 * @crossplatform 176 * @since 10 177 */ 178 export interface ExtraOptionsBase { 179 /** 180 * Size of the receive buffer, in MBS. 181 * @type {?number} 182 * @syscap SystemCapability.Communication.NetStack 183 * @since 7 184 */ 185 /** 186 * Size of the receive buffer, in MBS. 187 * @type {?number} 188 * @syscap SystemCapability.Communication.NetStack 189 * @crossplatform 190 * @since 10 191 */ 192 receiveBufferSize?: number; 193 194 /** 195 * Size of the send buffer, in MBS. 196 * @type {?number} 197 * @syscap SystemCapability.Communication.NetStack 198 * @since 7 199 */ 200 /** 201 * Size of the send buffer, in MBS. 202 * @type {?number} 203 * @syscap SystemCapability.Communication.NetStack 204 * @crossplatform 205 * @since 10 206 */ 207 sendBufferSize?: number; 208 209 /** 210 * Whether to reuse addresses. The default value is false. 211 * @type {?boolean} 212 * @syscap SystemCapability.Communication.NetStack 213 * @since 7 214 */ 215 /** 216 * Whether to reuse addresses. The default value is false. 217 * @type {?boolean} 218 * @syscap SystemCapability.Communication.NetStack 219 * @crossplatform 220 * @since 10 221 */ 222 reuseAddress?: boolean; 223 224 /** 225 * Timeout duration of the UDPSocket connection, in milliseconds. 226 * @type {?number} 227 * @syscap SystemCapability.Communication.NetStack 228 * @since 7 229 */ 230 /** 231 * Timeout duration of the UDPSocket connection, in milliseconds. 232 * @type {?number} 233 * @syscap SystemCapability.Communication.NetStack 234 * @crossplatform 235 * @since 10 236 */ 237 socketTimeout?: number; 238 } 239 240 /** 241 * Defines other properties of the UDPSocket connection. 242 * @interface UDPExtraOptions 243 * @syscap SystemCapability.Communication.NetStack 244 * @since 7 245 */ 246 /** 247 * Defines other properties of the UDPSocket connection. 248 * @interface UDPExtraOptions 249 * @syscap SystemCapability.Communication.NetStack 250 * @crossplatform 251 * @since 10 252 */ 253 export interface UDPExtraOptions extends ExtraOptionsBase { 254 /** 255 * Whether to send broadcast messages. The default value is false. 256 * @type {?boolean} 257 * @syscap SystemCapability.Communication.NetStack 258 * @since 7 259 */ 260 /** 261 * Whether to send broadcast messages. The default value is false. 262 * @type {?boolean} 263 * @syscap SystemCapability.Communication.NetStack 264 * @crossplatform 265 * @since 10 266 */ 267 broadcast?: boolean; 268 } 269 270 /** 271 * Defines the status of the socket connection. 272 * @interface SocketStateBase 273 * @syscap SystemCapability.Communication.NetStack 274 * @since 7 275 */ 276 /** 277 * Defines the status of the socket connection. 278 * @interface SocketStateBase 279 * @syscap SystemCapability.Communication.NetStack 280 * @crossplatform 281 * @since 10 282 */ 283 export interface SocketStateBase { 284 /** 285 * Whether the connection is in the bound state. 286 * @type {boolean} 287 * @syscap SystemCapability.Communication.NetStack 288 * @since 7 289 */ 290 /** 291 * Whether the connection is in the bound state. 292 * @type {boolean} 293 * @syscap SystemCapability.Communication.NetStack 294 * @crossplatform 295 * @since 10 296 */ 297 isBound: boolean; 298 299 /** 300 * Whether the connection is in the closed state. 301 * @type {boolean} 302 * @syscap SystemCapability.Communication.NetStack 303 * @since 7 304 */ 305 /** 306 * Whether the connection is in the closed state. 307 * @type {boolean} 308 * @syscap SystemCapability.Communication.NetStack 309 * @crossplatform 310 * @since 10 311 */ 312 isClose: boolean; 313 314 /** 315 * Whether the connection is in the connected state. 316 * @type {boolean} 317 * @syscap SystemCapability.Communication.NetStack 318 * @since 7 319 */ 320 /** 321 * Whether the connection is in the connected state. 322 * @type {boolean} 323 * @syscap SystemCapability.Communication.NetStack 324 * @crossplatform 325 * @since 10 326 */ 327 isConnected: boolean; 328 } 329 330 /** 331 * Defines information about the socket connection. 332 * @interface SocketRemoteInfo 333 * @syscap SystemCapability.Communication.NetStack 334 * @since 7 335 */ 336 /** 337 * Defines information about the socket connection. 338 * @interface SocketRemoteInfo 339 * @syscap SystemCapability.Communication.NetStack 340 * @crossplatform 341 * @since 10 342 */ 343 export interface SocketRemoteInfo { 344 /** 345 * Bound IP address. 346 * @type {string} 347 * @syscap SystemCapability.Communication.NetStack 348 * @since 7 349 */ 350 /** 351 * Bound IP address. 352 * @type {string} 353 * @syscap SystemCapability.Communication.NetStack 354 * @crossplatform 355 * @since 10 356 */ 357 address: string; 358 359 /** 360 * Network protocol type. The options are as follows: IPv4, IPv6. 361 * @type {'IPv4' | 'IPv6'} 362 * @syscap SystemCapability.Communication.NetStack 363 * @since 7 364 */ 365 /** 366 * Network protocol type. The options are as follows: IPv4, IPv6. 367 * @type {'IPv4' | 'IPv6'} 368 * @syscap SystemCapability.Communication.NetStack 369 * @crossplatform 370 * @since 10 371 */ 372 family: 'IPv4' | 'IPv6'; 373 374 /** 375 * Port number. The value ranges from 0 to 65535. 376 * @type {number} 377 * @syscap SystemCapability.Communication.NetStack 378 * @since 7 379 */ 380 /** 381 * Port number. The value ranges from 0 to 65535. 382 * @type {number} 383 * @syscap SystemCapability.Communication.NetStack 384 * @crossplatform 385 * @since 10 386 */ 387 port: number; 388 389 /** 390 * Length of the server response message, in bytes. 391 * @type {number} 392 * @syscap SystemCapability.Communication.NetStack 393 * @since 7 394 */ 395 /** 396 * Length of the server response message, in bytes. 397 * @type {number} 398 * @syscap SystemCapability.Communication.NetStack 399 * @crossplatform 400 * @since 10 401 */ 402 size: number; 403 } 404 405 /** 406 * Defines a UDPSocket connection. 407 * @interface UDPSocket 408 * @syscap SystemCapability.Communication.NetStack 409 * @since 7 410 */ 411 /** 412 * Defines a UDPSocket connection. 413 * @interface UDPSocket 414 * @syscap SystemCapability.Communication.NetStack 415 * @crossplatform 416 * @since 10 417 */ 418 export interface UDPSocket { 419 /** 420 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 421 * @permission ohos.permission.INTERNET 422 * @param { NetAddress } address - Destination address. {@link NetAddress} 423 * @param { AsyncCallback<void> } callback - the callback of bind. 424 * @throws { BusinessError } 401 - Parameter error. 425 * @throws { BusinessError } 201 - Permission denied. 426 * @syscap SystemCapability.Communication.NetStack 427 * @since 7 428 */ 429 /** 430 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 431 * @permission ohos.permission.INTERNET 432 * @param { NetAddress } address - Destination address. {@link NetAddress} 433 * @param { AsyncCallback<void> } callback - the callback of bind. 434 * @throws { BusinessError } 401 - Parameter error. 435 * @throws { BusinessError } 201 - Permission denied. 436 * @syscap SystemCapability.Communication.NetStack 437 * @crossplatform 438 * @since 10 439 */ 440 bind(address: NetAddress, callback: AsyncCallback<void>): void; 441 442 /** 443 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 444 * @permission ohos.permission.INTERNET 445 * @param { NetAddress } address - Destination address. {@link NetAddress} 446 * @returns { Promise<void> } The promise returned by the function. 447 * @throws { BusinessError } 401 - Parameter error. 448 * @throws { BusinessError } 201 - Permission denied. 449 * @syscap SystemCapability.Communication.NetStack 450 * @since 7 451 */ 452 /** 453 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 454 * @permission ohos.permission.INTERNET 455 * @param { NetAddress } address - Destination address. {@link NetAddress} 456 * @returns { Promise<void> } The promise returned by the function. 457 * @throws { BusinessError } 401 - Parameter error. 458 * @throws { BusinessError } 201 - Permission denied. 459 * @syscap SystemCapability.Communication.NetStack 460 * @crossplatform 461 * @since 10 462 */ 463 bind(address: NetAddress): Promise<void>; 464 465 /** 466 * Sends data over a UDPSocket connection. 467 * @permission ohos.permission.INTERNET 468 * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}. 469 * @param { AsyncCallback<void> } callback - the callback of send. 470 * @throws { BusinessError } 401 - Parameter error. 471 * @throws { BusinessError } 201 - Permission denied. 472 * @syscap SystemCapability.Communication.NetStack 473 * @since 7 474 */ 475 /** 476 * Sends data over a UDPSocket connection. 477 * @permission ohos.permission.INTERNET 478 * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}. 479 * @param { AsyncCallback<void> } callback - the callback of send. 480 * @throws { BusinessError } 401 - Parameter error. 481 * @throws { BusinessError } 201 - Permission denied. 482 * @syscap SystemCapability.Communication.NetStack 483 * @crossplatform 484 * @since 10 485 */ 486 send(options: UDPSendOptions, callback: AsyncCallback<void>): void; 487 488 /** 489 * Sends data over a UDPSocket connection. 490 * @permission ohos.permission.INTERNET 491 * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}. 492 * @returns { Promise<void> } The promise returned by the function. 493 * @throws { BusinessError } 401 - Parameter error. 494 * @throws { BusinessError } 201 - Permission denied. 495 * @syscap SystemCapability.Communication.NetStack 496 * @since 7 497 */ 498 /** 499 * Sends data over a UDPSocket connection. 500 * @permission ohos.permission.INTERNET 501 * @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}. 502 * @returns { Promise<void> } The promise returned by the function. 503 * @throws { BusinessError } 401 - Parameter error. 504 * @throws { BusinessError } 201 - Permission denied. 505 * @syscap SystemCapability.Communication.NetStack 506 * @crossplatform 507 * @since 10 508 */ 509 send(options: UDPSendOptions): Promise<void>; 510 511 /** 512 * Closes a UDPSocket connection. 513 * @permission ohos.permission.INTERNET 514 * @param { AsyncCallback<void> } callback - the callback of close. 515 * @throws { BusinessError } 201 - Permission denied. 516 * @syscap SystemCapability.Communication.NetStack 517 * @since 7 518 */ 519 /** 520 * Closes a UDPSocket connection. 521 * @permission ohos.permission.INTERNET 522 * @param { AsyncCallback<void> } callback - the callback of close. 523 * @throws { BusinessError } 201 - Permission denied. 524 * @syscap SystemCapability.Communication.NetStack 525 * @crossplatform 526 * @since 10 527 */ 528 close(callback: AsyncCallback<void>): void; 529 530 /** 531 * Closes a UDPSocket connection. 532 * @permission ohos.permission.INTERNET 533 * @returns { Promise<void> } The promise returned by the function. 534 * @throws { BusinessError } 201 - Permission denied. 535 * @syscap SystemCapability.Communication.NetStack 536 * @since 7 537 */ 538 /** 539 * Closes a UDPSocket connection. 540 * @permission ohos.permission.INTERNET 541 * @returns { Promise<void> } The promise returned by the function. 542 * @throws { BusinessError } 201 - Permission denied. 543 * @syscap SystemCapability.Communication.NetStack 544 * @crossplatform 545 * @since 10 546 */ 547 close(): Promise<void>; 548 549 /** 550 * Obtains the status of the UDPSocket connection. 551 * @permission ohos.permission.INTERNET 552 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}. 553 * @throws { BusinessError } 201 - Permission denied. 554 * @syscap SystemCapability.Communication.NetStack 555 * @since 7 556 */ 557 /** 558 * Obtains the status of the UDPSocket connection. 559 * @permission ohos.permission.INTERNET 560 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}. 561 * @throws { BusinessError } 201 - Permission denied. 562 * @syscap SystemCapability.Communication.NetStack 563 * @crossplatform 564 * @since 10 565 */ 566 getState(callback: AsyncCallback<SocketStateBase>): void; 567 568 /** 569 * Obtains the status of the UDPSocket connection. 570 * @permission ohos.permission.INTERNET 571 * @returns { Promise<SocketStateBase> } The promise returned by the function. 572 * @throws { BusinessError } 201 - Permission denied. 573 * @syscap SystemCapability.Communication.NetStack 574 * @since 7 575 */ 576 /** 577 * Obtains the status of the UDPSocket connection. 578 * @permission ohos.permission.INTERNET 579 * @returns { Promise<SocketStateBase> } The promise returned by the function. 580 * @throws { BusinessError } 201 - Permission denied. 581 * @syscap SystemCapability.Communication.NetStack 582 * @crossplatform 583 * @since 10 584 */ 585 getState(): Promise<SocketStateBase>; 586 587 /** 588 * Sets other attributes of the UDPSocket connection. 589 * @permission ohos.permission.INTERNET 590 * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}. 591 * @param { AsyncCallback<void> }callback - the callback of setExtraOptions. 592 * @throws { BusinessError } 401 - Parameter error. 593 * @throws { BusinessError } 201 - Permission denied. 594 * @syscap SystemCapability.Communication.NetStack 595 * @since 7 596 */ 597 /** 598 * Sets other attributes of the UDPSocket connection. 599 * @permission ohos.permission.INTERNET 600 * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}. 601 * @param { AsyncCallback<void> }callback - the callback of setExtraOptions. 602 * @throws { BusinessError } 401 - Parameter error. 603 * @throws { BusinessError } 201 - Permission denied. 604 * @syscap SystemCapability.Communication.NetStack 605 * @crossplatform 606 * @since 10 607 */ 608 setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback<void>): void; 609 610 /** 611 * Sets other attributes of the UDPSocket connection. 612 * @permission ohos.permission.INTERNET 613 * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}. 614 * @returns { Promise<void> } The promise returned by the function. 615 * @throws { BusinessError } 401 - Parameter error. 616 * @throws { BusinessError } 201 - Permission denied. 617 * @syscap SystemCapability.Communication.NetStack 618 * @since 7 619 */ 620 /** 621 * Sets other attributes of the UDPSocket connection. 622 * @permission ohos.permission.INTERNET 623 * @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}. 624 * @returns { Promise<void> } The promise returned by the function. 625 * @throws { BusinessError } 401 - Parameter error. 626 * @throws { BusinessError } 201 - Permission denied. 627 * @syscap SystemCapability.Communication.NetStack 628 * @crossplatform 629 * @since 10 630 */ 631 setExtraOptions(options: UDPExtraOptions): Promise<void>; 632 633 /** 634 * Listens for message receiving events of the UDPSocket connection. 635 * @param { 'message' } type - Indicates Event name. 636 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 637 * @syscap SystemCapability.Communication.NetStack 638 * @since 7 639 */ 640 /** 641 * Listens for message receiving events of the UDPSocket connection. 642 * @param { 'message' } type - Indicates Event name. 643 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 644 * @syscap SystemCapability.Communication.NetStack 645 * @crossplatform 646 * @since 10 647 */ 648 on(type: 'message', callback: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 649 650 /** 651 * Cancels listening for message receiving events of the UDPSocket connection. 652 * @param { 'message' } type - Indicates Event name. 653 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 654 * @syscap SystemCapability.Communication.NetStack 655 * @since 7 656 */ 657 /** 658 * Cancels listening for message receiving events of the UDPSocket connection. 659 * @param { 'message' } type - Indicates Event name. 660 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 661 * @syscap SystemCapability.Communication.NetStack 662 * @crossplatform 663 * @since 10 664 */ 665 off(type: 'message', callback?: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 666 667 /** 668 * Listens for data packet message events or close events of the UDPSocket connection. 669 * @param { 'listening' | 'close' } type - Indicates Event name. 670 * @param { Callback<void> } callback - the callback used to return the result. 671 * @syscap SystemCapability.Communication.NetStack 672 * @since 7 673 */ 674 /** 675 * Listens for data packet message events or close events of the UDPSocket connection. 676 * @param { 'listening' | 'close' } type - Indicates Event name. 677 * @param { Callback<void> } callback - the callback used to return the result. 678 * @syscap SystemCapability.Communication.NetStack 679 * @crossplatform 680 * @since 10 681 */ 682 on(type: 'listening' | 'close', callback: Callback<void>): void; 683 684 /** 685 * Cancels listening for data packet message events or close events of the UDPSocket connection. 686 * @param { 'listening' | 'close' } type - Indicates Event name. 687 * @param { Callback<void> } callback - the callback used to return the result. 688 * @syscap SystemCapability.Communication.NetStack 689 * @since 7 690 */ 691 /** 692 * Cancels listening for data packet message events or close events of the UDPSocket connection. 693 * @param { 'listening' | 'close' } type - Indicates Event name. 694 * @param { Callback<void> } callback - the callback used to return the result. 695 * @syscap SystemCapability.Communication.NetStack 696 * @crossplatform 697 * @since 10 698 */ 699 off(type: 'listening' | 'close', callback?: Callback<void>): void; 700 701 /** 702 * Listens for error events of the UDPSocket connection. 703 * @param { 'error' } type - Indicates Event name. 704 * @param { ErrorCallback } callback - the callback used to return the result. 705 * @syscap SystemCapability.Communication.NetStack 706 * @since 7 707 */ 708 /** 709 * Listens for error events of the UDPSocket connection. 710 * @param { 'error' } type - Indicates Event name. 711 * @param { ErrorCallback } callback - the callback used to return the result. 712 * @syscap SystemCapability.Communication.NetStack 713 * @crossplatform 714 * @since 10 715 */ 716 on(type: 'error', callback: ErrorCallback): void; 717 718 /** 719 * Cancels listening for error events of the UDPSocket connection. 720 * @param { 'error' } type - Indicates Event name. 721 * @param { ErrorCallback } callback - the callback used to return the result. 722 * @syscap SystemCapability.Communication.NetStack 723 * @since 7 724 */ 725 /** 726 * Cancels listening for error events of the UDPSocket connection. 727 * @param { 'error' } type - Indicates Event name. 728 * @param { ErrorCallback } callback - the callback used to return the result. 729 * @syscap SystemCapability.Communication.NetStack 730 * @crossplatform 731 * @since 10 732 */ 733 off(type: 'error', callback?: ErrorCallback): void; 734 } 735 736 /** 737 * Defines a UDP MulticastSocket connection. 738 * @interface MulticastSocket 739 * @syscap SystemCapability.Communication.NetStack 740 * @since 11 741 */ 742 export interface MulticastSocket extends UDPSocket { 743 /** 744 * Add the socket to the multicast group. 745 * @permission ohos.permission.INTERNET 746 * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}. 747 * @param { AsyncCallback<void> } callback - The callback of addMembership. 748 * @throws { BusinessError } 201 - Permission denied. 749 * @throws { BusinessError } 401 - Parameter error. 750 * @throws { BusinessError } 2301022 - Invalid argument. 751 * @throws { BusinessError } 2301088 - Not a socket. 752 * @throws { BusinessError } 2301098 - Address in use. 753 * @syscap SystemCapability.Communication.NetStack 754 * @since 11 755 */ 756 addMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void; 757 758 /** 759 * Add the socket to the multicast group. 760 * @permission ohos.permission.INTERNET 761 * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}. 762 * @returns { Promise<void> } The promise returned by the function. 763 * @throws { BusinessError } 201 - Permission denied. 764 * @throws { BusinessError } 401 - Parameter error. 765 * @throws { BusinessError } 2301088 - Not a socket. 766 * @throws { BusinessError } 2301098 - Address in use. 767 * @syscap SystemCapability.Communication.NetStack 768 * @since 11 769 */ 770 addMembership(multicastAddress: NetAddress): Promise<void>; 771 772 /** 773 * Drop the socket from the multicast group. 774 * @permission ohos.permission.INTERNET 775 * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}. 776 * @param { AsyncCallback<void> } callback - The callback of dropMembership. 777 * @throws { BusinessError } 201 - Permission denied. 778 * @throws { BusinessError } 401 - Parameter error. 779 * @throws { BusinessError } 2301088 - Not a socket. 780 * @throws { BusinessError } 2301098 - Address in use. 781 * @syscap SystemCapability.Communication.NetStack 782 * @since 11 783 */ 784 dropMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void; 785 786 /** 787 * Drop the socket from the multicast group. 788 * @permission ohos.permission.INTERNET 789 * @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}. 790 * @returns { Promise<void> } The promise returned by the function. 791 * @throws { BusinessError } 201 - Permission denied. 792 * @throws { BusinessError } 401 - Parameter error. 793 * @throws { BusinessError } 2301088 - Not a socket. 794 * @throws { BusinessError } 2301098 - Address in use. 795 * @syscap SystemCapability.Communication.NetStack 796 * @since 11 797 */ 798 dropMembership(multicastAddress: NetAddress): Promise<void>; 799 800 /** 801 * Set the TTL value for socket multicast packets. 802 * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255. 803 * @param { AsyncCallback<void> } callback - The callback of setMulticastTTL. 804 * @throws { BusinessError } 401 - Parameter error. 805 * @throws { BusinessError } 2301022 - Invalid argument. 806 * @throws { BusinessError } 2301088 - Not a socket. 807 * @syscap SystemCapability.Communication.NetStack 808 * @since 11 809 */ 810 setMulticastTTL(ttl: number, callback: AsyncCallback<void>): void; 811 812 /** 813 * Set the TTL value for socket multicast packet. 814 * @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255. 815 * @returns { Promise<void> } The promise returned by the function. 816 * @throws { BusinessError } 401 - Parameter error. 817 * @throws { BusinessError } 2301022 - Invalid argument. 818 * @throws { BusinessError } 2301088 - Not a socket. 819 * @syscap SystemCapability.Communication.NetStack 820 * @since 11 821 */ 822 setMulticastTTL(ttl: number): Promise<void>; 823 824 /** 825 * Get the TTL value of socket multicast packet. 826 * @param { AsyncCallback<number> } callback - The callback of getMulticastTTL. 827 * @throws { BusinessError } 401 - Parameter error. 828 * @throws { BusinessError } 2301088 - Not a socket. 829 * @syscap SystemCapability.Communication.NetStack 830 * @since 11 831 */ 832 getMulticastTTL(callback: AsyncCallback<number>): void; 833 834 /** 835 * Get the TTL value of socket multicast packet. 836 * @returns { Promise<number> } The promise returned by the function. 837 * @throws { BusinessError } 401 - Parameter error. 838 * @throws { BusinessError } 2301088 - Not a socket. 839 * @syscap SystemCapability.Communication.NetStack 840 * @since 11 841 */ 842 getMulticastTTL(): Promise<number>; 843 844 /** 845 * Set the loopback mode for the socket. 846 * @param { boolean } flag - Whether to enable loopback mode. 847 * @param { AsyncCallback<void> } callback - The callback of setLoopbackMode. 848 * @throws { BusinessError } 401 - Parameter error. 849 * @throws { BusinessError } 2301088 - Not a socket. 850 * @syscap SystemCapability.Communication.NetStack 851 * @since 11 852 */ 853 setLoopbackMode(flag: boolean, callback: AsyncCallback<void>): void; 854 855 /** 856 * Set the loopback mode for the socket. 857 * @param { boolean } flag - Whether to enable loopback mode. 858 * @returns { Promise<void> } The promise returned by the function. 859 * @throws { BusinessError } 401 - Parameter error. 860 * @throws { BusinessError } 2301088 - Not a socket. 861 * @syscap SystemCapability.Communication.NetStack 862 * @since 11 863 */ 864 setLoopbackMode(flag: boolean): Promise<void>; 865 866 /** 867 * Get the loopback mode of the socket. 868 * @param { AsyncCallback<boolean> } callback - The callback of getLoopbackMode. 869 * @throws { BusinessError } 401 - Parameter error. 870 * @throws { BusinessError } 2301088 - Not a socket. 871 * @syscap SystemCapability.Communication.NetStack 872 * @since 11 873 */ 874 getLoopbackMode(callback: AsyncCallback<boolean>): void; 875 876 /** 877 * Get the loopback mode of the socket. 878 * @returns { Promise<boolean> } The promise returned by the function. 879 * @throws { BusinessError } 401 - Parameter error. 880 * @throws { BusinessError } 2301088 - Not a socket. 881 * @syscap SystemCapability.Communication.NetStack 882 * @since 11 883 */ 884 getLoopbackMode(): Promise<boolean>; 885 } 886 887 /** 888 * Defines TCPSocket connection parameters. 889 * @interface TCPConnectOptions 890 * @syscap SystemCapability.Communication.NetStack 891 * @since 7 892 */ 893 /** 894 * Defines TCPSocket connection parameters. 895 * @interface TCPConnectOptions 896 * @syscap SystemCapability.Communication.NetStack 897 * @crossplatform 898 * @since 10 899 */ 900 export interface TCPConnectOptions { 901 /** 902 * Bound IP address and port number. 903 * @type { NetAddress } 904 * @syscap SystemCapability.Communication.NetStack 905 * @since 7 906 */ 907 /** 908 * Bound IP address and port number. 909 * @type { NetAddress } 910 * @syscap SystemCapability.Communication.NetStack 911 * @crossplatform 912 * @since 10 913 */ 914 address: NetAddress; 915 916 /** 917 * Timeout duration of the TCPSocket connection, in milliseconds. 918 * @type { ?number } 919 * @syscap SystemCapability.Communication.NetStack 920 * @since 7 921 */ 922 /** 923 * Timeout duration of the TCPSocket connection, in milliseconds. 924 * @type { ?number } 925 * @syscap SystemCapability.Communication.NetStack 926 * @crossplatform 927 * @since 10 928 */ 929 timeout?: number; 930 } 931 932 /** 933 * Defines the parameters for sending data over the TCPSocket connection. 934 * @interface TCPSendOptions 935 * @syscap SystemCapability.Communication.NetStack 936 * @since 7 937 */ 938 /** 939 * Defines the parameters for sending data over the TCPSocket connection. 940 * @interface TCPSendOptions 941 * @syscap SystemCapability.Communication.NetStack 942 * @crossplatform 943 * @since 10 944 */ 945 export interface TCPSendOptions { 946 /** 947 * Data to send. 948 * @type { string | ArrayBuffer } 949 * @syscap SystemCapability.Communication.NetStack 950 * @since 7 951 */ 952 /** 953 * Data to send. 954 * @type { string | ArrayBuffer } 955 * @syscap SystemCapability.Communication.NetStack 956 * @crossplatform 957 * @since 10 958 */ 959 data: string | ArrayBuffer; 960 961 /** 962 * Character encoding format. 963 * @type { ?string } 964 * @syscap SystemCapability.Communication.NetStack 965 * @since 7 966 */ 967 /** 968 * Character encoding format. 969 * @type { ?string } 970 * @syscap SystemCapability.Communication.NetStack 971 * @crossplatform 972 * @since 10 973 */ 974 encoding?: string; 975 } 976 977 /** 978 * Defines other properties of the TCPSocket connection. 979 * @interface TCPExtraOptions 980 * @syscap SystemCapability.Communication.NetStack 981 * @since 7 982 */ 983 /** 984 * Defines other properties of the TCPSocket connection. 985 * @interface TCPExtraOptions 986 * @syscap SystemCapability.Communication.NetStack 987 * @crossplatform 988 * @since 10 989 */ 990 export interface TCPExtraOptions extends ExtraOptionsBase { 991 /** 992 * Whether to keep the connection alive. The default value is false. 993 * @type { ?boolean } 994 * @syscap SystemCapability.Communication.NetStack 995 * @since 7 996 */ 997 /** 998 * Whether to keep the connection alive. The default value is false. 999 * @type { ?boolean } 1000 * @syscap SystemCapability.Communication.NetStack 1001 * @crossplatform 1002 * @since 10 1003 */ 1004 keepAlive?: boolean; 1005 1006 /** 1007 * Whether to enable OOBInline. The default value is false. 1008 * @type { ?boolean } 1009 * @syscap SystemCapability.Communication.NetStack 1010 * @since 7 1011 */ 1012 /** 1013 * Whether to enable OOBInline. The default value is false. 1014 * @type { ?boolean } 1015 * @syscap SystemCapability.Communication.NetStack 1016 * @crossplatform 1017 * @since 10 1018 */ 1019 OOBInline?: boolean; 1020 1021 /** 1022 * Whether to enable no-delay on the TCPSocket connection. The default value is false. 1023 * @type { ?boolean } 1024 * @syscap SystemCapability.Communication.NetStack 1025 * @since 7 1026 */ 1027 /** 1028 * Whether to enable no-delay on the TCPSocket connection. The default value is false. 1029 * @type { ?boolean } 1030 * @syscap SystemCapability.Communication.NetStack 1031 * @crossplatform 1032 * @since 10 1033 */ 1034 TCPNoDelay?: boolean; 1035 1036 /** 1037 * Socket linger. 1038 * @type { ?object } 1039 * @syscap SystemCapability.Communication.NetStack 1040 * @crossplatform 1041 * @since 7 1042 */ 1043 /** 1044 * Socket linger. 1045 * @type { ?object } 1046 * @syscap SystemCapability.Communication.NetStack 1047 * @crossplatform 1048 * @since 10 1049 */ 1050 socketLinger?: { on: boolean, linger: number }; 1051 } 1052 1053 /** 1054 * Defines a TCPSocket connection. 1055 * @interface TCPSocket 1056 * @syscap SystemCapability.Communication.NetStack 1057 * @since 7 1058 */ 1059 /** 1060 * Defines a TCPSocket connection. 1061 * @interface TCPSocket 1062 * @syscap SystemCapability.Communication.NetStack 1063 * @crossplatform 1064 * @since 10 1065 */ 1066 export interface TCPSocket { 1067 /** 1068 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1069 * @permission ohos.permission.INTERNET 1070 * @param { NetAddress } address - Destination address. {@link NetAddress} 1071 * @param { AsyncCallback<void> } callback - Return the callback of bind. 1072 * @throws { BusinessError } 401 - Parameter error. 1073 * @throws { BusinessError } 201 - Permission denied. 1074 * @syscap SystemCapability.Communication.NetStack 1075 * @since 7 1076 */ 1077 /** 1078 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1079 * @permission ohos.permission.INTERNET 1080 * @param { NetAddress } address - Destination address. {@link NetAddress} 1081 * @param { AsyncCallback<void> } callback - the callback of bind. 1082 * @throws { BusinessError } 401 - Parameter error. 1083 * @throws { BusinessError } 201 - Permission denied. 1084 * @syscap SystemCapability.Communication.NetStack 1085 * @crossplatform 1086 * @since 10 1087 */ 1088 bind(address: NetAddress, callback: AsyncCallback<void>): void; 1089 1090 /** 1091 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1092 * @permission ohos.permission.INTERNET 1093 * @param { NetAddress } address - Destination address. {@link NetAddress} 1094 * @returns { Promise<void> } The promise returned by the function. 1095 * @throws { BusinessError } 401 - Parameter error. 1096 * @throws { BusinessError } 201 - Permission denied. 1097 * @syscap SystemCapability.Communication.NetStack 1098 * @since 7 1099 */ 1100 /** 1101 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1102 * @permission ohos.permission.INTERNET 1103 * @param { NetAddress } address - Destination address. {@link NetAddress} 1104 * @returns { Promise<void> } The promise returned by the function. 1105 * @throws { BusinessError } 401 - Parameter error. 1106 * @throws { BusinessError } 201 - Permission denied. 1107 * @syscap SystemCapability.Communication.NetStack 1108 * @crossplatform 1109 * @since 10 1110 */ 1111 bind(address: NetAddress): Promise<void>; 1112 1113 /** 1114 * Sets up a connection to the specified IP address and port number. 1115 * @permission ohos.permission.INTERNET 1116 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 1117 * @param { AsyncCallback<void> } callback - the callback of connect. 1118 * @throws { BusinessError } 401 - Parameter error. 1119 * @throws { BusinessError } 201 - Permission denied. 1120 * @syscap SystemCapability.Communication.NetStack 1121 * @since 7 1122 */ 1123 /** 1124 * Sets up a connection to the specified IP address and port number. 1125 * @permission ohos.permission.INTERNET 1126 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 1127 * @param { AsyncCallback<void> } callback - the callback of connect. 1128 * @throws { BusinessError } 401 - Parameter error. 1129 * @throws { BusinessError } 201 - Permission denied. 1130 * @syscap SystemCapability.Communication.NetStack 1131 * @crossplatform 1132 * @since 10 1133 */ 1134 connect(options: TCPConnectOptions, callback: AsyncCallback<void>): void; 1135 1136 /** 1137 * Sets up a connection to the specified IP address and port number. 1138 * @permission ohos.permission.INTERNET 1139 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 1140 * @returns { Promise<void> } The promise returned by the function. 1141 * @throws { BusinessError } 401 - Parameter error. 1142 * @throws { BusinessError } 201 - Permission denied. 1143 * @syscap SystemCapability.Communication.NetStack 1144 * @since 7 1145 */ 1146 /** 1147 * Sets up a connection to the specified IP address and port number. 1148 * @permission ohos.permission.INTERNET 1149 * @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}. 1150 * @returns { Promise<void> } The promise returned by the function. 1151 * @throws { BusinessError } 401 - Parameter error. 1152 * @throws { BusinessError } 201 - Permission denied. 1153 * @syscap SystemCapability.Communication.NetStack 1154 * @crossplatform 1155 * @since 10 1156 */ 1157 connect(options: TCPConnectOptions): Promise<void>; 1158 1159 /** 1160 * Sends data over a TCPSocket connection. 1161 * @permission ohos.permission.INTERNET 1162 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 1163 * @param { AsyncCallback<void> } callback - the callback of send. 1164 * @throws { BusinessError } 401 - Parameter error. 1165 * @throws { BusinessError } 201 - Permission denied. 1166 * @syscap SystemCapability.Communication.NetStack 1167 * @since 7 1168 */ 1169 /** 1170 * Sends data over a TCPSocket connection. 1171 * @permission ohos.permission.INTERNET 1172 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 1173 * @param { AsyncCallback<void> } callback - the callback of send. 1174 * @throws { BusinessError } 401 - Parameter error. 1175 * @throws { BusinessError } 201 - Permission denied. 1176 * @syscap SystemCapability.Communication.NetStack 1177 * @crossplatform 1178 * @since 10 1179 */ 1180 send(options: TCPSendOptions, callback: AsyncCallback<void>): void; 1181 1182 /** 1183 * Sends data over a TCPSocket connection. 1184 * @permission ohos.permission.INTERNET 1185 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 1186 * @returns { Promise<void> } The promise returned by the function. 1187 * @throws { BusinessError } 401 - Parameter error. 1188 * @throws { BusinessError } 201 - Permission denied. 1189 * @syscap SystemCapability.Communication.NetStack 1190 * @since 7 1191 */ 1192 /** 1193 * Sends data over a TCPSocket connection. 1194 * @permission ohos.permission.INTERNET 1195 * @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}. 1196 * @returns { Promise<void> } The promise returned by the function. 1197 * @throws { BusinessError } 401 - Parameter error. 1198 * @throws { BusinessError } 201 - Permission denied. 1199 * @syscap SystemCapability.Communication.NetStack 1200 * @crossplatform 1201 * @since 10 1202 */ 1203 send(options: TCPSendOptions): Promise<void>; 1204 1205 /** 1206 * Closes a TCPSocket connection. 1207 * @permission ohos.permission.INTERNET 1208 * @param { AsyncCallback<void> } callback - the callback of close. 1209 * @throws { BusinessError } 201 - Permission denied. 1210 * @syscap SystemCapability.Communication.NetStack 1211 * @since 7 1212 */ 1213 /** 1214 * Closes a TCPSocket connection. 1215 * @permission ohos.permission.INTERNET 1216 * @param { AsyncCallback<void> } callback - the callback of close. 1217 * @throws { BusinessError } 201 - Permission denied. 1218 * @syscap SystemCapability.Communication.NetStack 1219 * @crossplatform 1220 * @since 10 1221 */ 1222 close(callback: AsyncCallback<void>): void; 1223 1224 /** 1225 * Closes a TCPSocket connection. 1226 * @permission ohos.permission.INTERNET 1227 * @returns { Promise<void> } The promise returned by the function. 1228 * @throws { BusinessError } 201 - Permission denied. 1229 * @syscap SystemCapability.Communication.NetStack 1230 * @since 7 1231 */ 1232 /** 1233 * Closes a TCPSocket connection. 1234 * @permission ohos.permission.INTERNET 1235 * @returns { Promise<void> } The promise returned by the function. 1236 * @throws { BusinessError } 201 - Permission denied. 1237 * @syscap SystemCapability.Communication.NetStack 1238 * @crossplatform 1239 * @since 10 1240 */ 1241 close(): Promise<void>; 1242 1243 /** 1244 * Obtains the peer address of a TCPSocket connection. 1245 * @permission ohos.permission.INTERNET 1246 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress} 1247 * @throws { BusinessError } 201 - Permission denied. 1248 * @syscap SystemCapability.Communication.NetStack 1249 * @since 7 1250 */ 1251 /** 1252 * Obtains the peer address of a TCPSocket connection. 1253 * @permission ohos.permission.INTERNET 1254 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress} 1255 * @throws { BusinessError } 201 - Permission denied. 1256 * @syscap SystemCapability.Communication.NetStack 1257 * @crossplatform 1258 * @since 10 1259 */ 1260 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 1261 1262 /** 1263 * Obtains the peer address of a TCPSocket connection. 1264 * @permission ohos.permission.INTERNET 1265 * @returns { Promise<NetAddress> } The promise returned by the function. 1266 * @throws { BusinessError } 201 - Permission denied. 1267 * @syscap SystemCapability.Communication.NetStack 1268 * @since 7 1269 */ 1270 /** 1271 * Obtains the peer address of a TCPSocket connection. 1272 * @permission ohos.permission.INTERNET 1273 * @returns { Promise<NetAddress> } The promise returned by the function. 1274 * @throws { BusinessError } 201 - Permission denied. 1275 * @syscap SystemCapability.Communication.NetStack 1276 * @crossplatform 1277 * @since 10 1278 */ 1279 getRemoteAddress(): Promise<NetAddress>; 1280 1281 /** 1282 * Obtains the status of the TCPSocket connection. 1283 * @permission ohos.permission.INTERNET 1284 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase} 1285 * @throws { BusinessError } 201 - Permission denied. 1286 * @syscap SystemCapability.Communication.NetStack 1287 * @since 7 1288 */ 1289 /** 1290 * Obtains the status of the TCPSocket connection. 1291 * @permission ohos.permission.INTERNET 1292 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase} 1293 * @throws { BusinessError } 201 - Permission denied. 1294 * @syscap SystemCapability.Communication.NetStack 1295 * @crossplatform 1296 * @since 10 1297 */ 1298 getState(callback: AsyncCallback<SocketStateBase>): void; 1299 1300 /** 1301 * Obtains the status of the TCPSocket connection. 1302 * @permission ohos.permission.INTERNET 1303 * @returns { Promise<SocketStateBase> } The promise returned by the function. 1304 * @throws { BusinessError } 201 - Permission denied. 1305 * @syscap SystemCapability.Communication.NetStack 1306 * @since 7 1307 */ 1308 /** 1309 * Obtains the status of the TCPSocket connection. 1310 * @permission ohos.permission.INTERNET 1311 * @returns { Promise<SocketStateBase> } The promise returned by the function. 1312 * @throws { BusinessError } 201 - Permission denied. 1313 * @syscap SystemCapability.Communication.NetStack 1314 * @crossplatform 1315 * @since 10 1316 */ 1317 getState(): Promise<SocketStateBase>; 1318 1319 /** 1320 * Obtains the file descriptor of the TCPSocket connection. 1321 * @param { AsyncCallback<number> } callback - The callback returns the file descriptor of the TCPSocket connection. 1322 * @syscap SystemCapability.Communication.NetStack 1323 * @since 10 1324 */ 1325 getSocketFd(callback: AsyncCallback<number>): void; 1326 1327 /** 1328 * Obtains the file descriptor of the TCPSocket connection. 1329 * @returns { Promise<number> } The promise returns the file descriptor of the TCPSocket connection. 1330 * @syscap SystemCapability.Communication.NetStack 1331 * @since 10 1332 */ 1333 getSocketFd(): Promise<number>; 1334 1335 /** 1336 * Sets other attributes of the TCPSocket connection. 1337 * @permission ohos.permission.INTERNET 1338 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1339 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 1340 * @throws { BusinessError } 401 - Parameter error. 1341 * @throws { BusinessError } 201 - Permission denied. 1342 * @syscap SystemCapability.Communication.NetStack 1343 * @since 7 1344 */ 1345 /** 1346 * Sets other attributes of the TCPSocket connection. 1347 * @permission ohos.permission.INTERNET 1348 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1349 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 1350 * @throws { BusinessError } 401 - Parameter error. 1351 * @throws { BusinessError } 201 - Permission denied. 1352 * @syscap SystemCapability.Communication.NetStack 1353 * @crossplatform 1354 * @since 10 1355 */ 1356 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 1357 1358 /** 1359 * Sets other attributes of the TCPSocket connection. 1360 * @permission ohos.permission.INTERNET 1361 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1362 * @returns { Promise<void> } The promise returned by the function. 1363 * @throws { BusinessError } 401 - Parameter error. 1364 * @throws { BusinessError } 201 - Permission denied. 1365 * @syscap SystemCapability.Communication.NetStack 1366 * @since 7 1367 */ 1368 /** 1369 * Sets other attributes of the TCPSocket connection. 1370 * @permission ohos.permission.INTERNET 1371 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1372 * @returns { Promise<void> } The promise returned by the function. 1373 * @throws { BusinessError } 401 - Parameter error. 1374 * @throws { BusinessError } 201 - Permission denied. 1375 * @syscap SystemCapability.Communication.NetStack 1376 * @crossplatform 1377 * @since 10 1378 */ 1379 setExtraOptions(options: TCPExtraOptions): Promise<void>; 1380 1381 /** 1382 * Listens for message receiving events of the TCPSocket connection. 1383 * @param { 'message' } type - Indicates Event name. 1384 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1385 * @syscap SystemCapability.Communication.NetStack 1386 * @since 7 1387 */ 1388 /** 1389 * Listens for message receiving events of the TCPSocket connection. 1390 * @param { 'message' } type Indicates Event name. 1391 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1392 * @syscap SystemCapability.Communication.NetStack 1393 * @crossplatform 1394 * @since 10 1395 */ 1396 on(type: 'message', callback: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 1397 1398 /** 1399 * Cancels listening for message receiving events of the TCPSocket connection. 1400 * @param { 'message' } type Indicates Event name. 1401 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1402 * @syscap SystemCapability.Communication.NetStack 1403 * @since 7 1404 */ 1405 /** 1406 * Cancels listening for message receiving events of the TCPSocket connection. 1407 * @param { 'message' } type Indicates Event name. 1408 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1409 * @syscap SystemCapability.Communication.NetStack 1410 * @crossplatform 1411 * @since 10 1412 */ 1413 off(type: 'message', callback?: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 1414 1415 1416 /** 1417 * Listens for connection or close events of the TCPSocket connection. 1418 * @param { 'connect' | 'close' } type - Indicates Event name. 1419 * @param { Callback<void> } callback - the callback used to return the result. 1420 * @syscap SystemCapability.Communication.NetStack 1421 * @since 7 1422 */ 1423 /** 1424 * Listens for connection or close events of the TCPSocket connection. 1425 * @param { 'connect' | 'close' } type - Indicates Event name. 1426 * @param { Callback<void> } callback - the callback used to return the result. 1427 * @syscap SystemCapability.Communication.NetStack 1428 * @crossplatform 1429 * @since 10 1430 */ 1431 on(type: 'connect' | 'close', callback: Callback<void>): void; 1432 1433 /** 1434 * Cancels listening for connection or close events of the TCPSocket connection. 1435 * @param { 'connect' | 'close' } type - Indicates Event name. 1436 * @param { Callback<void> } callback - the callback used to return the result. 1437 * @syscap SystemCapability.Communication.NetStack 1438 * @since 7 1439 */ 1440 /** 1441 * Cancels listening for connection or close events of the TCPSocket connection. 1442 * @param { 'connect' | 'close' } type - Indicates Event name. 1443 * @param { Callback<void> } callback - the callback used to return the result. 1444 * @syscap SystemCapability.Communication.NetStack 1445 * @crossplatform 1446 * @since 10 1447 */ 1448 off(type: 'connect' | 'close', callback?: Callback<void>): void; 1449 1450 /** 1451 * Listens for error events of the TCPSocket connection. 1452 * @param { 'error' } type - Indicates Event name. 1453 * @param { ErrorCallback } callback - the callback used to return the result. 1454 * @syscap SystemCapability.Communication.NetStack 1455 * @since 7 1456 */ 1457 /** 1458 * Listens for error events of the TCPSocket connection. 1459 * @param { 'error' } type - Indicates Event name. 1460 * @param { ErrorCallback } callback - the callback used to return the result. 1461 * @syscap SystemCapability.Communication.NetStack 1462 * @crossplatform 1463 * @since 10 1464 */ 1465 on(type: 'error', callback: ErrorCallback): void; 1466 1467 /** 1468 * Cancels listening for error events of the TCPSocket connection. 1469 * @param { 'error' } type - Indicates Event name. 1470 * @param { ErrorCallback } callback - the callback used to return the result. 1471 * @syscap SystemCapability.Communication.NetStack 1472 * @since 7 1473 */ 1474 /** 1475 * Cancels listening for error events of the TCPSocket connection. 1476 * @param { 'error' } type - Indicates Event name. 1477 * @param { ErrorCallback } callback - the callback used to return the result. 1478 * @syscap SystemCapability.Communication.NetStack 1479 * @crossplatform 1480 * @since 10 1481 */ 1482 off(type: 'error', callback?: ErrorCallback): void; 1483 } 1484 1485 /** 1486 * Defines a TLSSocket connection. 1487 * @interface TLSSocket 1488 * @syscap SystemCapability.Communication.NetStack 1489 * @since 9 1490 */ 1491 /** 1492 * Defines a TLSSocket connection. 1493 * @interface TLSSocket 1494 * @syscap SystemCapability.Communication.NetStack 1495 * @crossplatform 1496 * @since 10 1497 */ 1498 export interface TLSSocket { 1499 /** 1500 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1501 * @permission ohos.permission.INTERNET 1502 * @param { NetAddress } address - Destination address. {@link NetAddress} 1503 * @param { AsyncCallback<void> } callback - the callback of bind. 1504 * @throws { BusinessError } 401 - Parameter error. 1505 * @throws { BusinessError } 201 - Permission denied. 1506 * @throws { BusinessError } 2303198 - Address already in use. 1507 * @throws { BusinessError } 2300002 - System internal error. 1508 * @syscap SystemCapability.Communication.NetStack 1509 * @since 9 1510 */ 1511 /** 1512 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1513 * @permission ohos.permission.INTERNET 1514 * @param { NetAddress } address - Destination address. {@link NetAddress} 1515 * @param { AsyncCallback<void> } callback - the callback of bind. 1516 * @throws { BusinessError } 401 - Parameter error. 1517 * @throws { BusinessError } 201 - Permission denied. 1518 * @throws { BusinessError } 2303198 - Address already in use. 1519 * @throws { BusinessError } 2300002 - System internal error. 1520 * @syscap SystemCapability.Communication.NetStack 1521 * @crossplatform 1522 * @since 10 1523 */ 1524 bind(address: NetAddress, callback: AsyncCallback<void>): void; 1525 1526 /** 1527 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1528 * @permission ohos.permission.INTERNET 1529 * @param { NetAddress } address - Destination address. {@link NetAddress} 1530 * @returns { Promise<void> } The promise returned by the function. 1531 * @throws { BusinessError } 401 - Parameter error. 1532 * @throws { BusinessError } 201 - Permission denied. 1533 * @throws { BusinessError } 2303198 - Address already in use. 1534 * @throws { BusinessError } 2300002 - System internal error. 1535 * @syscap SystemCapability.Communication.NetStack 1536 * @since 9 1537 */ 1538 /** 1539 * Binds the IP address and port number. The port number can be specified or randomly allocated by the system. 1540 * @permission ohos.permission.INTERNET 1541 * @param { NetAddress } address - Destination address. {@link NetAddress} 1542 * @returns { Promise<void> } The promise returned by the function. 1543 * @throws { BusinessError } 401 - Parameter error. 1544 * @throws { BusinessError } 201 - Permission denied. 1545 * @throws { BusinessError } 2303198 - Address already in use. 1546 * @throws { BusinessError } 2300002 - System internal error. 1547 * @syscap SystemCapability.Communication.NetStack 1548 * @crossplatform 1549 * @since 10 1550 */ 1551 bind(address: NetAddress): Promise<void>; 1552 1553 /** 1554 * Obtains the peer address of a TLSSocket connection. 1555 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. 1556 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1557 * @throws { BusinessError } 2300002 - System internal error. 1558 * @syscap SystemCapability.Communication.NetStack 1559 * @since 9 1560 */ 1561 /** 1562 * Obtains the peer address of a TLSSocket connection. 1563 * @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. 1564 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1565 * @throws { BusinessError } 2300002 - System internal error. 1566 * @syscap SystemCapability.Communication.NetStack 1567 * @crossplatform 1568 * @since 10 1569 */ 1570 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 1571 1572 /** 1573 * Obtains the peer address of a TLSSocket connection. 1574 * @returns { Promise<NetAddress> } The promise returned by the function. 1575 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1576 * @throws { BusinessError } 2300002 - System internal error. 1577 * @syscap SystemCapability.Communication.NetStack 1578 * @since 9 1579 */ 1580 /** 1581 * Obtains the peer address of a TLSSocket connection. 1582 * @returns { Promise<NetAddress> } The promise returned by the function. 1583 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1584 * @throws { BusinessError } 2300002 - System internal error. 1585 * @syscap SystemCapability.Communication.NetStack 1586 * @crossplatform 1587 * @since 10 1588 */ 1589 getRemoteAddress(): Promise<NetAddress>; 1590 1591 /** 1592 * Obtains the status of the TLSSocket connection. 1593 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. 1594 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1595 * @throws { BusinessError } 2300002 - System internal error. 1596 * @syscap SystemCapability.Communication.NetStack 1597 * @since 9 1598 */ 1599 /** 1600 * Obtains the status of the TLSSocket connection. 1601 * @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. 1602 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1603 * @throws { BusinessError } 2300002 - System internal error. 1604 * @syscap SystemCapability.Communication.NetStack 1605 * @crossplatform 1606 * @since 10 1607 */ 1608 getState(callback: AsyncCallback<SocketStateBase>): void; 1609 1610 /** 1611 * Obtains the status of the TLSSocket connection. 1612 * @returns { Promise<SocketStateBase> } The promise returned by the function. 1613 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1614 * @throws { BusinessError } 2300002 - System internal error. 1615 * @syscap SystemCapability.Communication.NetStack 1616 * @since 9 1617 */ 1618 /** 1619 * Obtains the status of the TLSSocket connection. 1620 * @returns { Promise<SocketStateBase> } The promise returned by the function. 1621 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1622 * @throws { BusinessError } 2300002 - System internal error. 1623 * @syscap SystemCapability.Communication.NetStack 1624 * @crossplatform 1625 * @since 10 1626 */ 1627 getState(): Promise<SocketStateBase>; 1628 1629 /** 1630 * Sets other attributes of the TLSSocket connection. 1631 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1632 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 1633 * @throws { BusinessError } 401 - Parameter error. 1634 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1635 * @throws { BusinessError } 2300002 - System internal error. 1636 * @syscap SystemCapability.Communication.NetStack 1637 * @since 9 1638 */ 1639 /** 1640 * Sets other attributes of the TLSSocket connection. 1641 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1642 * @param { AsyncCallback<void> } callback - the callback of setExtraOptions. 1643 * @throws { BusinessError } 401 - Parameter error. 1644 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1645 * @throws { BusinessError } 2300002 - System internal error. 1646 * @syscap SystemCapability.Communication.NetStack 1647 * @crossplatform 1648 * @since 10 1649 */ 1650 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 1651 1652 /** 1653 * Sets other attributes of the TLSSocket connection. 1654 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1655 * @returns { Promise<void> } The promise returned by the function. 1656 * @throws { BusinessError } 401 - Parameter error. 1657 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1658 * @throws { BusinessError } 2300002 - System internal error. 1659 * @syscap SystemCapability.Communication.NetStack 1660 * @since 9 1661 */ 1662 /** 1663 * Sets other attributes of the TLSSocket connection. 1664 * @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}. 1665 * @returns { Promise<void> } The promise returned by the function. 1666 * @throws { BusinessError } 401 - Parameter error. 1667 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 1668 * @throws { BusinessError } 2300002 - System internal error. 1669 * @syscap SystemCapability.Communication.NetStack 1670 * @crossplatform 1671 * @since 10 1672 */ 1673 setExtraOptions(options: TCPExtraOptions): Promise<void>; 1674 1675 /** 1676 * Listens for message receiving events of the TLSSocket connection. 1677 * @param { 'message' } type - Indicates Event name. 1678 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1679 * @throws { BusinessError } 401 - Parameter error. 1680 * @syscap SystemCapability.Communication.NetStack 1681 * @since 9 1682 */ 1683 /** 1684 * Listens for message receiving events of the TLSSocket connection. 1685 * @param { 'message' } type Indicates Event name. 1686 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1687 * @throws { BusinessError } 401 - Parameter error. 1688 * @syscap SystemCapability.Communication.NetStack 1689 * @crossplatform 1690 * @since 10 1691 */ 1692 on(type: 'message', callback: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 1693 1694 /** 1695 * Cancels listening for message receiving events of the TLSSocket connection. 1696 * @param { 'message' } type - Indicates Event name. 1697 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1698 * @throws { BusinessError } 401 - Parameter error. 1699 * @syscap SystemCapability.Communication.NetStack 1700 * @since 9 1701 */ 1702 /** 1703 * Cancels listening for message receiving events of the TLSSocket connection. 1704 * @param { 'message' } type Indicates Event name. 1705 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result. 1706 * @throws { BusinessError } 401 - Parameter error. 1707 * @syscap SystemCapability.Communication.NetStack 1708 * @crossplatform 1709 * @since 10 1710 */ 1711 off(type: 'message', callback?: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 1712 1713 /** 1714 * Listens for connection or close events of the TLSSocket connection. 1715 * @param { 'connect' | 'close' } type - Indicates Event name. 1716 * @param {Callback<void> } callback - the callback used to return the result. 1717 * @throws { BusinessError } 401 - Parameter error. 1718 * @syscap SystemCapability.Communication.NetStack 1719 * @since 9 1720 */ 1721 /** 1722 * Listens for connection or close events of the TLSSocket connection. 1723 * @param { 'connect' | 'close' } type - Indicates Event name. 1724 * @param {Callback<void> } callback - the callback used to return the result. 1725 * @throws { BusinessError } 401 - Parameter error. 1726 * @syscap SystemCapability.Communication.NetStack 1727 * @crossplatform 1728 * @since 10 1729 */ 1730 on(type: 'connect' | 'close', callback: Callback<void>): void; 1731 1732 /** 1733 * Cancels listening for connection or close events of the TLSSocket connection. 1734 * @param { 'connect' | 'close' } type - Indicates Event name. 1735 * @param {Callback<void> } callback - the callback used to return the result. 1736 * @throws { BusinessError } 401 - Parameter error. 1737 * @syscap SystemCapability.Communication.NetStack 1738 * @since 9 1739 */ 1740 /** 1741 * Cancels listening for connection or close events of the TLSSocket connection. 1742 * @param { 'connect' | 'close' } type - Indicates Event name. 1743 * @param {Callback<void> } callback - the callback used to return the result. 1744 * @throws { BusinessError } 401 - Parameter error. 1745 * @syscap SystemCapability.Communication.NetStack 1746 * @crossplatform 1747 * @since 10 1748 */ 1749 off(type: 'connect' | 'close', callback?: Callback<void>): void; 1750 1751 /** 1752 * Listens for error events of the TLSSocket connection. 1753 * @param { 'error' } type - Indicates Event name. 1754 * @param { ErrorCallback } callback - the callback used to return the result. 1755 * @throws { BusinessError } 401 - Parameter error. 1756 * @syscap SystemCapability.Communication.NetStack 1757 * @since 9 1758 */ 1759 /** 1760 * Listens for error events of the TLSSocket connection. 1761 * @param { 'error' } type - Indicates Event name. 1762 * @param { ErrorCallback } callback - the callback used to return the result. 1763 * @throws { BusinessError } 401 - Parameter error. 1764 * @syscap SystemCapability.Communication.NetStack 1765 * @crossplatform 1766 * @since 10 1767 */ 1768 on(type: 'error', callback: ErrorCallback): void; 1769 1770 /** 1771 * Cancels listening for error events of the TLSSocket connection. 1772 * @param { 'error' } type - Indicates Event name. 1773 * @param { ErrorCallback } callback - the callback used to return the result. 1774 * @throws { BusinessError } 401 - Parameter error. 1775 * @syscap SystemCapability.Communication.NetStack 1776 * @since 9 1777 */ 1778 /** 1779 * Cancels listening for error events of the TLSSocket connection. 1780 * @param { 'error' } type - Indicates Event name. 1781 * @param { ErrorCallback } callback - the callback used to return the result. 1782 * @throws { BusinessError } 401 - Parameter error. 1783 * @syscap SystemCapability.Communication.NetStack 1784 * @crossplatform 1785 * @since 10 1786 */ 1787 off(type: 'error', callback?: ErrorCallback): void; 1788 1789 /** 1790 * Returns an object representing a local certificate. 1791 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate. 1792 * @throws { BusinessError } 2303501 - SSL is null. 1793 * @throws { BusinessError } 2303504 - Error looking up x509 1794 * @throws { BusinessError } 2300002 - System internal error. 1795 * @syscap SystemCapability.Communication.NetStack 1796 * @since 9 1797 */ 1798 /** 1799 * Returns an object representing a local certificate. 1800 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate. 1801 * @throws { BusinessError } 2303501 - SSL is null. 1802 * @throws { BusinessError } 2303504 - Error looking up x509 1803 * @throws { BusinessError } 2300002 - System internal error. 1804 * @syscap SystemCapability.Communication.NetStack 1805 * @crossplatform 1806 * @since 10 1807 */ 1808 getCertificate(callback: AsyncCallback<X509CertRawData>): void; 1809 1810 /** 1811 * Returns an object representing a local certificate. 1812 * @returns { Promise<X509CertRawData> } The promise returned by the function. 1813 * @throws { BusinessError } 2303501 - SSL is null. 1814 * @throws { BusinessError } 2303504 - Error looking up x509 1815 * @throws { BusinessError } 2300002 - System internal error. 1816 * @syscap SystemCapability.Communication.NetStack 1817 * @since 9 1818 */ 1819 /** 1820 * Returns an object representing a local certificate. 1821 * @returns { Promise<X509CertRawData> } The promise returned by the function. 1822 * @throws { BusinessError } 2303501 - SSL is null. 1823 * @throws { BusinessError } 2303504 - Error looking up x509 1824 * @throws { BusinessError } 2300002 - System internal error. 1825 * @syscap SystemCapability.Communication.NetStack 1826 * @crossplatform 1827 * @since 10 1828 */ 1829 getCertificate(): Promise<X509CertRawData>; 1830 1831 /** 1832 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 1833 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 1834 * It only contains the peer's certificate. 1835 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate. 1836 * @throws { BusinessError } 2303501 - SSL is null. 1837 * @throws { BusinessError } 2300002 - System internal error. 1838 * @syscap SystemCapability.Communication.NetStack 1839 * @since 9 1840 */ 1841 /** 1842 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 1843 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 1844 * It only contains the peer's certificate. 1845 * @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate. 1846 * @throws { BusinessError } 2303501 - SSL is null. 1847 * @throws { BusinessError } 2300002 - System internal error. 1848 * @syscap SystemCapability.Communication.NetStack 1849 * @crossplatform 1850 * @since 10 1851 */ 1852 getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void; 1853 1854 /** 1855 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 1856 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 1857 * It only contains the peer's certificate. 1858 * @returns { Promise<X509CertRawData> } The promise returned by the function. 1859 * @throws { BusinessError } 2303501 - SSL is null. 1860 * @throws { BusinessError } 2300002 - System internal error. 1861 * @syscap SystemCapability.Communication.NetStack 1862 * @since 9 1863 */ 1864 /** 1865 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 1866 * <p>an empty object will be returned. If the socket is destroyed, null is returned.</p> 1867 * It only contains the peer's certificate. 1868 * @returns { Promise<X509CertRawData> } The promise returned by the function. 1869 * @throws { BusinessError } 2303501 - SSL is null. 1870 * @throws { BusinessError } 2300002 - System internal error. 1871 * @syscap SystemCapability.Communication.NetStack 1872 * @crossplatform 1873 * @since 10 1874 */ 1875 getRemoteCertificate(): Promise<X509CertRawData>; 1876 1877 /** 1878 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 1879 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 1880 * Server sockets or disconnected client sockets will return a value of null. 1881 * @param { AsyncCallback<string> } callback - the callback of getProtocol. 1882 * @throws { BusinessError } 2303501 - SSL is null. 1883 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1884 * @throws { BusinessError } 2300002 - System internal error. 1885 * @syscap SystemCapability.Communication.NetStack 1886 * @since 9 1887 */ 1888 /** 1889 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 1890 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 1891 * Server sockets or disconnected client sockets will return a value of null. 1892 * @param { AsyncCallback<string> } callback - the callback of getProtocol. 1893 * @throws { BusinessError } 2303501 - SSL is null. 1894 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1895 * @throws { BusinessError } 2300002 - System internal error. 1896 * @syscap SystemCapability.Communication.NetStack 1897 * @crossplatform 1898 * @since 10 1899 */ 1900 getProtocol(callback: AsyncCallback<string>): void; 1901 1902 /** 1903 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 1904 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 1905 * Server sockets or disconnected client sockets will return a value of null. 1906 * @returns { Promise<string> } The promise returned by the function. 1907 * @throws { BusinessError } 2303501 - SSL is null. 1908 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1909 * @throws { BusinessError } 2300002 - System internal error. 1910 * @syscap SystemCapability.Communication.NetStack 1911 * @since 9 1912 */ 1913 /** 1914 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 1915 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 1916 * Server sockets or disconnected client sockets will return a value of null. 1917 * @returns { Promise<string> } The promise returned by the function. 1918 * @throws { BusinessError } 2303501 - SSL is null. 1919 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1920 * @throws { BusinessError } 2300002 - System internal error. 1921 * @syscap SystemCapability.Communication.NetStack 1922 * @crossplatform 1923 * @since 10 1924 */ 1925 getProtocol(): Promise<string>; 1926 1927 /** 1928 * Returns a list containing the negotiated cipher suite information. 1929 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 1930 * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite. 1931 * @throws { BusinessError } 2303501 - SSL is null. 1932 * @throws { BusinessError } 2303502 - Error in tls reading. 1933 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1934 * @throws { BusinessError } 2300002 - System internal error. 1935 * @syscap SystemCapability.Communication.NetStack 1936 * @since 9 1937 */ 1938 /** 1939 * Returns a list containing the negotiated cipher suite information. 1940 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 1941 * @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite. 1942 * @throws { BusinessError } 2303501 - SSL is null. 1943 * @throws { BusinessError } 2303502 - Error in tls reading. 1944 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1945 * @throws { BusinessError } 2300002 - System internal error. 1946 * @syscap SystemCapability.Communication.NetStack 1947 * @crossplatform 1948 * @since 10 1949 */ 1950 getCipherSuite(callback: AsyncCallback<Array<string>>): void; 1951 1952 /** 1953 * Returns a list containing the negotiated cipher suite information. 1954 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 1955 * @returns { Promise<Array<string>> } The promise returned by the function. 1956 * @throws { BusinessError } 2303501 - SSL is null. 1957 * @throws { BusinessError } 2303502 - Error in tls reading. 1958 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1959 * @throws { BusinessError } 2300002 - System internal error. 1960 * @syscap SystemCapability.Communication.NetStack 1961 * @since 9 1962 */ 1963 /** 1964 * Returns a list containing the negotiated cipher suite information. 1965 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 1966 * @returns { Promise<Array<string>> } The promise returned by the function. 1967 * @throws { BusinessError } 2303501 - SSL is null. 1968 * @throws { BusinessError } 2303502 - Error in tls reading. 1969 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 1970 * @throws { BusinessError } 2300002 - System internal error. 1971 * @syscap SystemCapability.Communication.NetStack 1972 * @crossplatform 1973 * @since 10 1974 */ 1975 getCipherSuite(): Promise<Array<string>>; 1976 1977 /** 1978 * <p>The list of signature algorithms shared between the server and the client, 1979 * in descending order of priority.</p> 1980 * @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html 1981 * @throws { BusinessError } 2303501 - SSL is null. 1982 * @throws { BusinessError } 2300002 - System internal error. 1983 * @syscap SystemCapability.Communication.NetStack 1984 * @since 9 1985 */ 1986 /** 1987 * <p>The list of signature algorithms shared between the server and the client, 1988 * in descending order of priority.</p> 1989 * @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html 1990 * @throws { BusinessError } 2303501 - SSL is null. 1991 * @throws { BusinessError } 2300002 - System internal error. 1992 * @syscap SystemCapability.Communication.NetStack 1993 * @crossplatform 1994 * @since 10 1995 */ 1996 getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void; 1997 1998 /** 1999 * <p>The list of signature algorithms shared between the server and the client, 2000 * in descending order of priority.</p> 2001 * @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 2002 * @throws { BusinessError } 2303501 - SSL is null. 2003 * @throws { BusinessError } 2300002 - System internal error. 2004 * @syscap SystemCapability.Communication.NetStack 2005 * @since 9 2006 */ 2007 /** 2008 * <p>The list of signature algorithms shared between the server and the client, 2009 * in descending order of priority.</p> 2010 * @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 2011 * @throws { BusinessError } 2303501 - SSL is null. 2012 * @throws { BusinessError } 2300002 - System internal error. 2013 * @syscap SystemCapability.Communication.NetStack 2014 * @crossplatform 2015 * @since 10 2016 */ 2017 getSignatureAlgorithms(): Promise<Array<string>>; 2018 2019 /** 2020 * Sets up a connection to the specified IP address and port number. 2021 * Only TCP is supported. 2022 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 2023 * @param { AsyncCallback<void> } callback - the callback of connect. 2024 * @throws { BusinessError } 401 - Parameter error. 2025 * @throws { BusinessError } 2303104 - Interrupted system call. 2026 * @throws { BusinessError } 2303109 - Bad file number. 2027 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2028 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2029 * @throws { BusinessError } 2303191 - Protocol wrong type for socket. 2030 * @throws { BusinessError } 2303198 - Address already in use. 2031 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2032 * @throws { BusinessError } 2303210 - Connection timed out. 2033 * @throws { BusinessError } 2303501 - SSL is null. 2034 * @throws { BusinessError } 2303502 - Error in tls reading. 2035 * @throws { BusinessError } 2303503 - Error in tls writing 2036 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2037 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2038 * @throws { BusinessError } 2300002 - System internal error. 2039 * @syscap SystemCapability.Communication.NetStack 2040 * @since 9 2041 */ 2042 /** 2043 * Sets up a connection to the specified IP address and port number. 2044 * Only TCP is supported. 2045 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 2046 * @param { AsyncCallback<void> } callback - the callback of connect. 2047 * @throws { BusinessError } 401 - Parameter error. 2048 * @throws { BusinessError } 2303104 - Interrupted system call. 2049 * @throws { BusinessError } 2303109 - Bad file number. 2050 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2051 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2052 * @throws { BusinessError } 2303191 - Protocol wrong type for socket. 2053 * @throws { BusinessError } 2303198 - Address already in use. 2054 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2055 * @throws { BusinessError } 2303210 - Connection timed out. 2056 * @throws { BusinessError } 2303501 - SSL is null. 2057 * @throws { BusinessError } 2303502 - Error in tls reading. 2058 * @throws { BusinessError } 2303503 - Error in tls writing 2059 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2060 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2061 * @throws { BusinessError } 2300002 - System internal error. 2062 * @syscap SystemCapability.Communication.NetStack 2063 * @crossplatform 2064 * @since 10 2065 */ 2066 connect(options: TLSConnectOptions, callback: AsyncCallback<void>): void; 2067 2068 /** 2069 * Sets up a connection to the specified IP address and port number. 2070 * Only TCP is supported. 2071 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 2072 * @returns { Promise<void> } The promise returned by the function. 2073 * @throws { BusinessError } 401 - Parameter error. 2074 * @throws { BusinessError } 2303104 - Interrupted system call. 2075 * @throws { BusinessError } 2303109 - Bad file number. 2076 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2077 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2078 * @throws { BusinessError } 2303191 - Protocol wrong type for socket. 2079 * @throws { BusinessError } 2303198 - Address already in use. 2080 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2081 * @throws { BusinessError } 2303210 - Connection timed out. 2082 * @throws { BusinessError } 2303501 - SSL is null. 2083 * @throws { BusinessError } 2303502 - Error in tls reading. 2084 * @throws { BusinessError } 2303503 - Error in tls writing 2085 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2086 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2087 * @throws { BusinessError } 2300002 - System internal error. 2088 * @syscap SystemCapability.Communication.NetStack 2089 * @since 9 2090 */ 2091 /** 2092 * Sets up a connection to the specified IP address and port number. 2093 * Only TCP is supported. 2094 * @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}. 2095 * @returns { Promise<void> } The promise returned by the function. 2096 * @throws { BusinessError } 401 - Parameter error. 2097 * @throws { BusinessError } 2303104 - Interrupted system call. 2098 * @throws { BusinessError } 2303109 - Bad file number. 2099 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2100 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2101 * @throws { BusinessError } 2303191 - Protocol wrong type for socket. 2102 * @throws { BusinessError } 2303198 - Address already in use. 2103 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2104 * @throws { BusinessError } 2303210 - Connection timed out. 2105 * @throws { BusinessError } 2303501 - SSL is null. 2106 * @throws { BusinessError } 2303502 - Error in tls reading. 2107 * @throws { BusinessError } 2303503 - Error in tls writing 2108 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2109 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2110 * @throws { BusinessError } 2300002 - System internal error. 2111 * @syscap SystemCapability.Communication.NetStack 2112 * @crossplatform 2113 * @since 10 2114 */ 2115 connect(options: TLSConnectOptions): Promise<void>; 2116 2117 /** 2118 * Sends data over a TLSSocket connection. 2119 * @param { string } data - Optional parameters {@link string}. 2120 * @param { AsyncCallback<void> } callback - the callback of send. 2121 * @throws { BusinessError } 401 - Parameter error. 2122 * @throws { BusinessError } 2303501 - SSL is null. 2123 * @throws { BusinessError } 2303503 - Error in tls writing. 2124 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2125 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2126 * @throws { BusinessError } 2300002 - System internal error. 2127 * @syscap SystemCapability.Communication.NetStack 2128 * @since 9 2129 */ 2130 /** 2131 * Sends data over a TLSSocket connection. 2132 * @param { string } data - Optional parameters {@link string}. 2133 * @param { AsyncCallback<void> } callback - the callback of send. 2134 * @throws { BusinessError } 401 - Parameter error. 2135 * @throws { BusinessError } 2303501 - SSL is null. 2136 * @throws { BusinessError } 2303503 - Error in tls writing. 2137 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2138 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2139 * @throws { BusinessError } 2300002 - System internal error. 2140 * @syscap SystemCapability.Communication.NetStack 2141 * @crossplatform 2142 * @since 10 2143 */ 2144 send(data: string, callback: AsyncCallback<void>): void; 2145 2146 /** 2147 * Sends data over a TLSSocket connection. 2148 * @param { string } data - Optional parameters {@link string}. 2149 * @returns { Promise<void> } The promise returned by the function. 2150 * @throws { BusinessError } 401 - Parameter error. 2151 * @throws { BusinessError } 2303501 - SSL is null. 2152 * @throws { BusinessError } 2303503 - Error in tls writing. 2153 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2154 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2155 * @throws { BusinessError } 2300002 - System internal error. 2156 * @syscap SystemCapability.Communication.NetStack 2157 * @since 9 2158 */ 2159 /** 2160 * Sends data over a TLSSocket connection. 2161 * @param { string } data - Optional parameters {@link string}. 2162 * @returns { Promise<void> } The promise returned by the function. 2163 * @throws { BusinessError } 401 - Parameter error. 2164 * @throws { BusinessError } 2303501 - SSL is null. 2165 * @throws { BusinessError } 2303503 - Error in tls writing. 2166 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2167 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2168 * @throws { BusinessError } 2300002 - System internal error. 2169 * @syscap SystemCapability.Communication.NetStack 2170 * @crossplatform 2171 * @since 10 2172 */ 2173 send(data: string): Promise<void>; 2174 2175 /** 2176 * Closes a TLSSocket connection 2177 * @param { AsyncCallback<void> } callback - the callback of close. 2178 * @throws { BusinessError } 401 - Parameter error. 2179 * @throws { BusinessError } 2303501 - SSL is null. 2180 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2181 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2182 * @throws { BusinessError } 2300002 - System internal error. 2183 * @syscap SystemCapability.Communication.NetStack 2184 * @since 9 2185 */ 2186 /** 2187 * Closes a TLSSocket connection 2188 * @param { AsyncCallback<void> } callback - the callback of close. 2189 * @throws { BusinessError } 401 - Parameter error. 2190 * @throws { BusinessError } 2303501 - SSL is null. 2191 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2192 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2193 * @throws { BusinessError } 2300002 - System internal error. 2194 * @syscap SystemCapability.Communication.NetStack 2195 * @crossplatform 2196 * @since 10 2197 */ 2198 close(callback: AsyncCallback<void>): void; 2199 2200 /** 2201 * Closes a TLSSocket connection 2202 * @returns { Promise<void> } The promise returned by the function. 2203 * @throws { BusinessError } 401 - Parameter error. 2204 * @throws { BusinessError } 2303501 - SSL is null. 2205 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2206 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2207 * @throws { BusinessError } 2300002 - System internal error. 2208 * @syscap SystemCapability.Communication.NetStack 2209 * @since 9 2210 */ 2211 /** 2212 * Closes a TLSSocket connection 2213 * @returns { Promise<void> } The promise returned by the function. 2214 * @throws { BusinessError } 401 - Parameter error. 2215 * @throws { BusinessError } 2303501 - SSL is null. 2216 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2217 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2218 * @throws { BusinessError } 2300002 - System internal error. 2219 * @syscap SystemCapability.Communication.NetStack 2220 * @crossplatform 2221 * @since 10 2222 */ 2223 close(): Promise<void>; 2224 } 2225 2226 /** 2227 * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional. 2228 * @interface TLSSecureOptions 2229 * @syscap SystemCapability.Communication.NetStack 2230 * @since 9 2231 */ 2232 /** 2233 * Defines TLS security options. The CA certificate is mandatory, and other parameters are optional. 2234 * @interface TLSSecureOptions 2235 * @syscap SystemCapability.Communication.NetStack 2236 * @crossplatform 2237 * @since 10 2238 */ 2239 export interface TLSSecureOptions { 2240 /** 2241 * Certificate used to verify the identity of the server 2242 * @type {string | Array<string>} 2243 * @syscap SystemCapability.Communication.NetStack 2244 * @since 9 2245 */ 2246 /** 2247 * Certificate used to verify the identity of the server 2248 * @type {string | Array<string>} 2249 * @syscap SystemCapability.Communication.NetStack 2250 * @crossplatform 2251 * @since 10 2252 */ 2253 ca: string | Array<string>; 2254 2255 /** 2256 * Certificate proving the identity of the client 2257 * @type {?string} 2258 * @syscap SystemCapability.Communication.NetStack 2259 * @since 9 2260 */ 2261 /** 2262 * Certificate proving the identity of the client 2263 * @type {?string} 2264 * @syscap SystemCapability.Communication.NetStack 2265 * @crossplatform 2266 * @since 10 2267 */ 2268 cert?: string; 2269 2270 /** 2271 * Private key of client certificate 2272 * @type {?string} 2273 * @syscap SystemCapability.Communication.NetStack 2274 * @since 9 2275 */ 2276 /** 2277 * Private key of client certificate 2278 * @type {?string} 2279 * @syscap SystemCapability.Communication.NetStack 2280 * @crossplatform 2281 * @since 10 2282 */ 2283 key?: string; 2284 2285 /** 2286 * Password of the private key 2287 * @type {?string} 2288 * @syscap SystemCapability.Communication.NetStack 2289 * @since 9 2290 */ 2291 /** 2292 * Password of the private key 2293 * @type {?string} 2294 * @syscap SystemCapability.Communication.NetStack 2295 * @crossplatform 2296 * @since 10 2297 */ 2298 password?: string; 2299 2300 /** 2301 * TLS protocol version 2302 * @type {?Protocol | Array<Protocol>} 2303 * @syscap SystemCapability.Communication.NetStack 2304 * @since 9 2305 */ 2306 /** 2307 * TLS protocol version 2308 * @type {?Protocol | Array<Protocol>} 2309 * @syscap SystemCapability.Communication.NetStack 2310 * @crossplatform 2311 * @since 10 2312 */ 2313 protocols?: Protocol | Array<Protocol>; 2314 2315 /** 2316 * default is false, use local cipher. 2317 * @type {?boolean} 2318 * @syscap SystemCapability.Communication.NetStack 2319 * @since 9 2320 */ 2321 /** 2322 * default is false, use local cipher. 2323 * @type {?boolean} 2324 * @syscap SystemCapability.Communication.NetStack 2325 * @crossplatform 2326 * @since 10 2327 */ 2328 useRemoteCipherPrefer?: boolean; 2329 2330 /** 2331 * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc), 2332 * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P> 2333 * @type {?string} 2334 * @syscap SystemCapability.Communication.NetStack 2335 * @since 9 2336 */ 2337 /** 2338 * <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc), 2339 * Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P> 2340 * @type {?string} 2341 * @syscap SystemCapability.Communication.NetStack 2342 * @crossplatform 2343 * @since 10 2344 */ 2345 signatureAlgorithms?: string; 2346 2347 /** 2348 * Crypto suite specification 2349 * @type {?string} 2350 * @syscap SystemCapability.Communication.NetStack 2351 * @since 9 2352 */ 2353 /** 2354 * Crypto suite specification 2355 * @type {?string} 2356 * @syscap SystemCapability.Communication.NetStack 2357 * @crossplatform 2358 * @since 10 2359 */ 2360 cipherSuite?: string; 2361 } 2362 2363 /** 2364 * Defines TLS connection options. 2365 * @interface TLSConnectOptions 2366 * @syscap SystemCapability.Communication.NetStack 2367 * @since 9 2368 */ 2369 /** 2370 * Defines TLS connection options. 2371 * @interface TLSConnectOptions 2372 * @syscap SystemCapability.Communication.NetStack 2373 * @crossplatform 2374 * @since 10 2375 */ 2376 export interface TLSConnectOptions { 2377 /** 2378 * Gateway address. 2379 * @type {NetAddress} 2380 * @syscap SystemCapability.Communication.NetStack 2381 * @since 9 2382 */ 2383 /** 2384 * Gateway address. 2385 * @type {NetAddress} 2386 * @syscap SystemCapability.Communication.NetStack 2387 * @crossplatform 2388 * @since 10 2389 */ 2390 address: NetAddress; 2391 2392 /** 2393 * Protocol http2TLS security related operations. 2394 * @type {TLSSecureOptions} 2395 * @syscap SystemCapability.Communication.NetStack 2396 * @since 9 2397 */ 2398 /** 2399 * Protocol http2TLS security related operations. 2400 * @type {TLSSecureOptions} 2401 * @syscap SystemCapability.Communication.NetStack 2402 * @crossplatform 2403 * @since 10 2404 */ 2405 secureOptions: TLSSecureOptions; 2406 2407 /** 2408 * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2" 2409 * @type {?Array<string>} 2410 * @syscap SystemCapability.Communication.NetStack 2411 * @since 9 2412 */ 2413 /** 2414 * Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2" 2415 * @type {?Array<string>} 2416 * @syscap SystemCapability.Communication.NetStack 2417 * @crossplatform 2418 * @since 10 2419 */ 2420 ALPNProtocols?: Array<string>; 2421 } 2422 2423 /** 2424 * Enumerates TLS protocol versions. 2425 * @enum {string} 2426 * @syscap SystemCapability.Communication.NetStack 2427 * @since 9 2428 */ 2429 /** 2430 * Enumerates TLS protocol versions. 2431 * @enum {string} 2432 * @syscap SystemCapability.Communication.NetStack 2433 * @crossplatform 2434 * @since 10 2435 */ 2436 export enum Protocol { 2437 /** 2438 * Use TLSv1.2 protocol for communication. 2439 * @syscap SystemCapability.Communication.NetStack 2440 * @since 9 2441 */ 2442 /** 2443 * Use TLSv1.2 protocol for communication. 2444 * @syscap SystemCapability.Communication.NetStack 2445 * @crossplatform 2446 * @since 10 2447 */ 2448 TLSv12 = "TLSv1.2", 2449 2450 /** 2451 * Use TLSv1.3 protocol for communication. 2452 * @syscap SystemCapability.Communication.NetStack 2453 * @since 9 2454 */ 2455 /** 2456 * Use TLSv1.3 protocol for communication. 2457 * @syscap SystemCapability.Communication.NetStack 2458 * @crossplatform 2459 * @since 10 2460 */ 2461 TLSv13 = "TLSv1.3" 2462 } 2463 2464 /** 2465 * Defines the connection of the TCPSocket client and server. 2466 * @interface TCPSocketConnection 2467 * @syscap SystemCapability.Communication.NetStack 2468 * @since 10 2469 */ 2470 export interface TCPSocketConnection { 2471 /** 2472 * The id of a client connects to the TCPSocketServer. 2473 * @type {number} 2474 * @syscap SystemCapability.Communication.NetStack 2475 * @since 10 2476 */ 2477 clientId: number; 2478 2479 /** 2480 * Sends data over a TCPSocketServer connection to client. 2481 * @permission ohos.permission.INTERNET 2482 * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}. 2483 * @param { AsyncCallback<void> } callback - The callback of send. 2484 * @throws { BusinessError } 201 - Permission denied. 2485 * @throws { BusinessError } 401 - Parameter error. 2486 * @throws { BusinessError } 2300002 - System internal error. 2487 * @syscap SystemCapability.Communication.NetStack 2488 * @since 10 2489 */ 2490 send(options: TCPSendOptions, callback: AsyncCallback<void>): void; 2491 2492 /** 2493 * Sends data over a TCPSocketServer connection to client. 2494 * @permission ohos.permission.INTERNET 2495 * @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}. 2496 * @returns { Promise<void> } The promise returned by the function. 2497 * @throws { BusinessError } 201 - Permission denied. 2498 * @throws { BusinessError } 401 - Parameter error. 2499 * @throws { BusinessError } 2300002 - System internal error. 2500 * @syscap SystemCapability.Communication.NetStack 2501 * @since 10 2502 */ 2503 send(options: TCPSendOptions): Promise<void>; 2504 2505 /** 2506 * Closes a TCPSocket client connection. 2507 * @permission ohos.permission.INTERNET 2508 * @param { AsyncCallback<void> } callback - The callback of close. 2509 * @throws { BusinessError } 201 - Permission denied. 2510 * @throws { BusinessError } 401 - Parameter error. 2511 * @throws { BusinessError } 2300002 - System internal error. 2512 * @syscap SystemCapability.Communication.NetStack 2513 * @since 10 2514 */ 2515 close(callback: AsyncCallback<void>): void; 2516 2517 /** 2518 * Closes a TCPSocket client connection. 2519 * @permission ohos.permission.INTERNET 2520 * @returns { Promise<void> } The promise returned by the function. 2521 * @throws { BusinessError } 201 - Permission denied. 2522 * @throws { BusinessError } 2300002 - System internal error. 2523 * @syscap SystemCapability.Communication.NetStack 2524 * @since 10 2525 */ 2526 close(): Promise<void>; 2527 2528 /** 2529 * Obtains the peer address of a TCPSocketServer connection. 2530 * @permission ohos.permission.INTERNET 2531 * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress. 2532 * @throws { BusinessError } 201 - Permission denied. 2533 * @throws { BusinessError } 401 - Parameter error. 2534 * @throws { BusinessError } 2300002 - System internal error. 2535 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2536 * @syscap SystemCapability.Communication.NetStack 2537 * @since 10 2538 */ 2539 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 2540 2541 /** 2542 * Obtains the peer address of a TCPSocketServer connection. 2543 * @permission ohos.permission.INTERNET 2544 * @returns { Promise<NetAddress> } The promise returned by the function. 2545 * @throws { BusinessError } 201 - Permission denied. 2546 * @throws { BusinessError } 2300002 - System internal error. 2547 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2548 * @syscap SystemCapability.Communication.NetStack 2549 * @since 10 2550 */ 2551 getRemoteAddress(): Promise<NetAddress>; 2552 2553 /** 2554 * Listens for message receiving events of the TCPSocketConnection. 2555 * @param { 'message' } type - Indicates Event name. 2556 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on. 2557 * @throws { BusinessError } 401 - Parameter error. 2558 * @syscap SystemCapability.Communication.NetStack 2559 * @since 10 2560 */ 2561 on(type: 'message', callback: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 2562 2563 /** 2564 * Cancels listening for message receiving events of the TCPSocketConnection. 2565 * @param { 'message' } type - Indicates Event name. 2566 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off. 2567 * @throws { BusinessError } 401 - Parameter error. 2568 * @syscap SystemCapability.Communication.NetStack 2569 * @since 10 2570 */ 2571 off(type: 'message', callback?: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 2572 2573 /** 2574 * Listens for close events of the TCPSocketConnection. 2575 * @param { 'close' } type - Indicates Event name. 2576 * @param { Callback<void> } callback - The callback of on. 2577 * @throws { BusinessError } 401 - Parameter error. 2578 * @syscap SystemCapability.Communication.NetStack 2579 * @since 10 2580 */ 2581 on(type: 'close', callback: Callback<void>): void; 2582 2583 /** 2584 * Cancels listening for close events of the TCPSocketConnection. 2585 * @param { 'close' } type - Indicates Event name. 2586 * @param { Callback<void> } callback - The callback of off. 2587 * @throws { BusinessError } 401 - Parameter error. 2588 * @syscap SystemCapability.Communication.NetStack 2589 * @since 10 2590 */ 2591 off(type: 'close', callback?: Callback<void>): void; 2592 2593 /** 2594 * Listens for error events of the TCPSocketConnection. 2595 * @param { 'error' } type - Indicates Event name. 2596 * @param { ErrorCallback } callback - The callback of on. 2597 * @throws { BusinessError } 401 - Parameter error. 2598 * @syscap SystemCapability.Communication.NetStack 2599 * @since 10 2600 */ 2601 on(type: 'error', callback: ErrorCallback): void; 2602 2603 /** 2604 * Cancels listening for error events of the TCPSocketConnection. 2605 * @param { 'error' } type - Indicates Event name. 2606 * @param { ErrorCallback } callback - The callback of off. 2607 * @throws { BusinessError } 401 - Parameter error. 2608 * @syscap SystemCapability.Communication.NetStack 2609 * @since 10 2610 */ 2611 off(type: 'error', callback?: ErrorCallback): void; 2612 } 2613 2614 /** 2615 * Defines a TCPSocket server connection. 2616 * @interface TCPSocketServer 2617 * @syscap SystemCapability.Communication.NetStack 2618 * @since 10 2619 */ 2620 export interface TCPSocketServer { 2621 /** 2622 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 2623 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 2624 * for accept processing and uses poll multiplex to process client connections.</p> 2625 * @permission ohos.permission.INTERNET 2626 * @param { NetAddress } address - Network address information {@link NetAddress}. 2627 * @param { AsyncCallback<void> } callback - The callback of listen. 2628 * @throws { BusinessError } 401 - Parameter error. 2629 * @throws { BusinessError } 201 - Permission denied. 2630 * @throws { BusinessError } 2300002 - System internal error. 2631 * @throws { BusinessError } 2303109 - Bad file number. 2632 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2633 * @throws { BusinessError } 2303198 - Address already in use. 2634 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2635 * @syscap SystemCapability.Communication.NetStack 2636 * @since 10 2637 */ 2638 listen(address: NetAddress, callback: AsyncCallback<void>): void; 2639 2640 /** 2641 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 2642 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 2643 * for accept processing and uses poll multiplex to process client connections.</p> 2644 * @permission ohos.permission.INTERNET 2645 * @param { NetAddress } address - Network address information {@link NetAddress}. 2646 * @returns { Promise<void> } The promise returned by the function. 2647 * @throws { BusinessError } 401 - Parameter error. 2648 * @throws { BusinessError } 201 - Permission denied. 2649 * @throws { BusinessError } 2300002 - System internal error. 2650 * @throws { BusinessError } 2303109 - Bad file number. 2651 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2652 * @throws { BusinessError } 2303198 - Address already in use. 2653 * @throws { BusinessError } 2303199 - Cannot assign requested address. 2654 * @syscap SystemCapability.Communication.NetStack 2655 * @since 10 2656 */ 2657 listen(address: NetAddress): Promise<void>; 2658 2659 /** 2660 * Obtains the status of the TCPSocketServer connection. 2661 * @permission ohos.permission.INTERNET 2662 * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState. 2663 * @throws { BusinessError } 201 - Permission denied. 2664 * @throws { BusinessError } 401 - Parameter error. 2665 * @throws { BusinessError } 2300002 - System internal error. 2666 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2667 * @syscap SystemCapability.Communication.NetStack 2668 * @since 10 2669 */ 2670 getState(callback: AsyncCallback<SocketStateBase>): void; 2671 2672 /** 2673 * Obtains the status of the TCPSocketServer connection. 2674 * @permission ohos.permission.INTERNET 2675 * @returns { Promise<SocketStateBase> } The promise returned by the function. 2676 * @throws { BusinessError } 201 - Permission denied. 2677 * @throws { BusinessError } 2300002 - System internal error. 2678 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2679 * @syscap SystemCapability.Communication.NetStack 2680 * @since 10 2681 */ 2682 getState(): Promise<SocketStateBase>; 2683 2684 /** 2685 * Sets other attributes of the TCPSocketServer connection. 2686 * @permission ohos.permission.INTERNET 2687 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 2688 * @param { AsyncCallback<void> } callback - The callback of setExtraOptions. 2689 * @throws { BusinessError } 201 - Permission denied. 2690 * @throws { BusinessError } 401 - Parameter error. 2691 * @throws { BusinessError } 2300002 - System internal error. 2692 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2693 * @syscap SystemCapability.Communication.NetStack 2694 * @since 10 2695 */ 2696 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 2697 2698 /** 2699 * Sets other attributes of the TCPSocketServer connection. 2700 * @permission ohos.permission.INTERNET 2701 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 2702 * @returns { Promise<void> } The promise returned by the function. 2703 * @throws { BusinessError } 201 - Permission denied. 2704 * @throws { BusinessError } 401 - Parameter error. 2705 * @throws { BusinessError } 2300002 - System internal error. 2706 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2707 * @syscap SystemCapability.Communication.NetStack 2708 * @since 10 2709 */ 2710 setExtraOptions(options: TCPExtraOptions): Promise<void>; 2711 2712 /** 2713 * Listens for connect events of the TCPSocketServer connection. 2714 * @param { 'connect' } type - Indicates Event name. 2715 * @param { Callback<TCPSocketConnection> } callback - The callback of on. 2716 * @throws { BusinessError } 401 - Parameter error. 2717 * @syscap SystemCapability.Communication.NetStack 2718 * @since 10 2719 */ 2720 on(type: 'connect', callback: Callback<TCPSocketConnection>): void; 2721 2722 /** 2723 * Cancels listening for connect events of the TCPSocketServer connection. 2724 * @param { 'connect' } type - Indicates Event name. 2725 * @param { Callback<TCPSocketConnection> } callback - The callback of off. 2726 * @throws { BusinessError } 401 - Parameter error. 2727 * @syscap SystemCapability.Communication.NetStack 2728 * @since 10 2729 */ 2730 off(type: 'connect', callback?: Callback<TCPSocketConnection>): void; 2731 2732 /** 2733 * Listens for error events of the TCPSocketServer connection. 2734 * @param { 'error' } type - Indicates Event name. 2735 * @param { ErrorCallback } callback - The callback of on. 2736 * @throws { BusinessError } 401 - Parameter error. 2737 * @syscap SystemCapability.Communication.NetStack 2738 * @since 10 2739 */ 2740 on(type: 'error', callback: ErrorCallback): void; 2741 2742 /** 2743 * Cancels listening for error events of the TCPSocketServer connection. 2744 * @param { 'error' } type - Indicates Event name. 2745 * @param { ErrorCallback } callback - The callback of off. 2746 * @throws { BusinessError } 401 - Parameter error. 2747 * @syscap SystemCapability.Communication.NetStack 2748 * @since 10 2749 */ 2750 off(type: 'error', callback?: ErrorCallback): void; 2751 } 2752 2753 /** 2754 * Defines the connection of the TLSSocket client and server. 2755 * @interface TLSSocketConnection 2756 * @syscap SystemCapability.Communication.NetStack 2757 * @since 10 2758 */ 2759 export interface TLSSocketConnection { 2760 /** 2761 * The id of a client connects to the TLSSocketServer. 2762 * @type {number} 2763 * @syscap SystemCapability.Communication.NetStack 2764 * @since 10 2765 */ 2766 clientId: number; 2767 2768 /** 2769 * Sends data over a TLSSocketServer connection to client. 2770 * @param { string } data - Parameters for sending data. 2771 * @param { AsyncCallback<void> } callback - The callback of send. 2772 * @throws { BusinessError } 401 - Parameter error. 2773 * @throws { BusinessError } 2303501 - SSL is null. 2774 * @throws { BusinessError } 2303503 - Error in tls writing. 2775 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2776 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2777 * @throws { BusinessError } 2300002 - System internal error. 2778 * @syscap SystemCapability.Communication.NetStack 2779 * @since 10 2780 */ 2781 send(data: string, callback: AsyncCallback<void>): void; 2782 2783 /** 2784 * Sends data over a TLSSocketServer connection to client. 2785 * @param { string } data - Parameters for sending data. 2786 * @returns { Promise<void> } The promise returned by the function. 2787 * @throws { BusinessError } 401 - Parameter error. 2788 * @throws { BusinessError } 2303501 - SSL is null. 2789 * @throws { BusinessError } 2303503 - Error in tls writing. 2790 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2791 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2792 * @throws { BusinessError } 2300002 - System internal error. 2793 * @syscap SystemCapability.Communication.NetStack 2794 * @since 10 2795 */ 2796 send(data: string): Promise<void>; 2797 2798 /** 2799 * Closes a TLSSocket client connection. 2800 * @param { AsyncCallback<void> } callback - The callback of close. 2801 * @throws { BusinessError } 401 - Parameter error. 2802 * @throws { BusinessError } 2303501 - SSL is null. 2803 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2804 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2805 * @throws { BusinessError } 2300002 - System internal error. 2806 * @syscap SystemCapability.Communication.NetStack 2807 * @since 10 2808 */ 2809 close(callback: AsyncCallback<void>): void; 2810 2811 /** 2812 * Closes a TLSSocket client connection. 2813 * @returns { Promise<void> } The promise returned by the function. 2814 * @throws { BusinessError } 2303501 - SSL is null. 2815 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2816 * @throws { BusinessError } 2303506 - Error clearing tls connection. 2817 * @throws { BusinessError } 2300002 - System internal error. 2818 * @syscap SystemCapability.Communication.NetStack 2819 * @since 10 2820 */ 2821 close(): Promise<void>; 2822 2823 /** 2824 * Obtains the peer address of a TLSSocketServer connection. 2825 * @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress. 2826 * @throws { BusinessError } 401 - Parameter error. 2827 * @throws { BusinessError } 2300002 - System internal error. 2828 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2829 * @syscap SystemCapability.Communication.NetStack 2830 * @since 10 2831 */ 2832 getRemoteAddress(callback: AsyncCallback<NetAddress>): void; 2833 2834 /** 2835 * Obtains the peer address of a TLSSocketServer connection. 2836 * @returns { Promise<NetAddress> } The promise returned by the function. 2837 * @throws { BusinessError } 2300002 - System internal error. 2838 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 2839 * @syscap SystemCapability.Communication.NetStack 2840 * @since 10 2841 */ 2842 getRemoteAddress(): Promise<NetAddress>; 2843 2844 /** 2845 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 2846 * an empty object will be returned. If the socket is destroyed, null is returned.</p> 2847 * It only contains the peer's certificate. 2848 * @param { AsyncCallback<X509CertRawData> } callback - The callback of getRemoteCertificate. 2849 * @throws { BusinessError } 401 - Parameter error. 2850 * @throws { BusinessError } 2303501 - SSL is null. 2851 * @throws { BusinessError } 2300002 - System internal error. 2852 * @syscap SystemCapability.Communication.NetStack 2853 * @since 10 2854 */ 2855 getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void; 2856 2857 /** 2858 * <p>Returns an object representing the peer certificate. If the peer does not provide a certificate, 2859 * an empty object will be returned. If the socket is destroyed, null is returned.</p> 2860 * It only contains the peer's certificate. 2861 * @returns { Promise<X509CertRawData> } The promise returned by the function. 2862 * @throws { BusinessError } 2303501 - SSL is null. 2863 * @throws { BusinessError } 2300002 - System internal error. 2864 * @syscap SystemCapability.Communication.NetStack 2865 * @since 10 2866 */ 2867 getRemoteCertificate(): Promise<X509CertRawData>; 2868 2869 /** 2870 * Returns a list containing the negotiated cipher suite information. 2871 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 2872 * @param { AsyncCallback<Array<string>> } callback - The callback of getCipherSuite. 2873 * @throws { BusinessError } 401 - Parameter error. 2874 * @throws { BusinessError } 2303501 - SSL is null. 2875 * @throws { BusinessError } 2303502 - Error in tls reading. 2876 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2877 * @throws { BusinessError } 2300002 - System internal error. 2878 * @syscap SystemCapability.Communication.NetStack 2879 * @since 10 2880 */ 2881 getCipherSuite(callback: AsyncCallback<Array<string>>): void; 2882 2883 /** 2884 * Returns a list containing the negotiated cipher suite information. 2885 * For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"} 2886 * @returns { Promise<Array<string>> } The promise returned by the function. 2887 * @throws { BusinessError } 2303501 - SSL is null. 2888 * @throws { BusinessError } 2303502 - Error in tls reading. 2889 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 2890 * @throws { BusinessError } 2300002 - System internal error. 2891 * @syscap SystemCapability.Communication.NetStack 2892 * @since 10 2893 */ 2894 getCipherSuite(): Promise<Array<string>>; 2895 2896 /** 2897 * <p>The list of signature algorithms shared between the server and the client, 2898 * in descending order of priority.</p> 2899 * @param { AsyncCallback<Array<string>> } callback - The callback of getSignatureAlgorithms. 2900 * @throws { BusinessError } 401 - Parameter error. 2901 * @throws { BusinessError } 2303501 - SSL is null. 2902 * @throws { BusinessError } 2300002 - System internal error. 2903 * @syscap SystemCapability.Communication.NetStack 2904 * @since 10 2905 */ 2906 getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void; 2907 2908 /** 2909 * <p>The list of signature algorithms shared between the server and the client, 2910 * in descending order of priority.</p> 2911 * @returns { Promise<Array<string>> } The promise returned by the function. 2912 * @throws { BusinessError } 2303501 - SSL is null. 2913 * @throws { BusinessError } 2300002 - System internal error. 2914 * @syscap SystemCapability.Communication.NetStack 2915 * @since 10 2916 */ 2917 getSignatureAlgorithms(): Promise<Array<string>>; 2918 2919 /** 2920 * Listens for message receiving events of the TLSSocketConnection. 2921 * @param { 'message' } type - Indicates Event name. 2922 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on. 2923 * @throws { BusinessError } 401 - Parameter error. 2924 * @syscap SystemCapability.Communication.NetStack 2925 * @since 10 2926 */ 2927 on(type: 'message', callback: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 2928 2929 /** 2930 * Cancels listening for message receiving events of the TLSSocketConnection. 2931 * @param { 'message' } type - Indicates Event name. 2932 * @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off. 2933 * @throws { BusinessError } 401 - Parameter error. 2934 * @syscap SystemCapability.Communication.NetStack 2935 * @since 10 2936 */ 2937 off(type: 'message', callback?: Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }>): void; 2938 2939 /** 2940 * Listens for close events of the TLSSocketConnection. 2941 * @param { 'close' } type - Indicates Event name. 2942 * @param { Callback<void> } callback - The callback of on. 2943 * @throws { BusinessError } 401 - Parameter error. 2944 * @syscap SystemCapability.Communication.NetStack 2945 * @since 10 2946 */ 2947 on(type: 'close', callback: Callback<void>): void; 2948 2949 /** 2950 * Cancels listening for close events of the TLSSocketConnection. 2951 * @param { 'close' } type - Indicates Event name. 2952 * @param { Callback<void> } callback - The callback of off. 2953 * @throws { BusinessError } 401 - Parameter error. 2954 * @syscap SystemCapability.Communication.NetStack 2955 * @since 10 2956 */ 2957 off(type: 'close', callback?: Callback<void>): void; 2958 2959 /** 2960 * Listens for error events of the TLSSocketConnection. 2961 * @param { 'error' } type - Indicates Event name. 2962 * @param { ErrorCallback } callback - The callback of on. 2963 * @throws { BusinessError } 401 - Parameter error. 2964 * @syscap SystemCapability.Communication.NetStack 2965 * @since 10 2966 */ 2967 on(type: 'error', callback: ErrorCallback): void; 2968 2969 /** 2970 * Cancels listening for error events of the TLSSocketConnection. 2971 * @param { 'error' } type - Indicates Event name. 2972 * @param { ErrorCallback } callback - The callback of off. 2973 * @throws { BusinessError } 401 - Parameter error. 2974 * @syscap SystemCapability.Communication.NetStack 2975 * @since 10 2976 */ 2977 off(type: 'error', callback?: ErrorCallback): void; 2978 } 2979 2980 /** 2981 * Defines a TLSSocketServer server connection. 2982 * @interface TLSSocketServer 2983 * @syscap SystemCapability.Communication.NetStack 2984 * @since 10 2985 */ 2986 export interface TLSSocketServer { 2987 /** 2988 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 2989 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 2990 * for accept processing and uses poll multiplex to process client connections.</p> 2991 * @permission ohos.permission.INTERNET 2992 * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}. 2993 * @param { AsyncCallback<void> } callback - The callback of listen. 2994 * @throws { BusinessError } 401 - Parameter error. 2995 * @throws { BusinessError } 201 - Permission denied. 2996 * @throws { BusinessError } 2300002 - System internal error. 2997 * @throws { BusinessError } 2303109 - Bad file number. 2998 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 2999 * @throws { BusinessError } 2303198 - Address already in use. 3000 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3001 * @throws { BusinessError } 2303501 - SSL is null. 3002 * @throws { BusinessError } 2303502 - Error in tls reading. 3003 * @throws { BusinessError } 2303503 - Error in tls writing 3004 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 3005 * @throws { BusinessError } 2303506 - Error clearing tls connection. 3006 * @syscap SystemCapability.Communication.NetStack 3007 * @since 10 3008 */ 3009 listen(options: TLSConnectOptions, callback: AsyncCallback<void>): void; 3010 3011 /** 3012 * Binds the IP address and port number, the port number can be specified or randomly allocated by the system. 3013 * <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads 3014 * for accept processing and uses poll multiplex to process client connections.</p> 3015 * @permission ohos.permission.INTERNET 3016 * @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}. 3017 * @returns { Promise<void> } The promise returned by the function. 3018 * @throws { BusinessError } 401 - Parameter error. 3019 * @throws { BusinessError } 201 - Permission denied. 3020 * @throws { BusinessError } 2300002 - System internal error. 3021 * @throws { BusinessError } 2303109 - Bad file number. 3022 * @throws { BusinessError } 2303111 - Resource temporarily unavailable try again. 3023 * @throws { BusinessError } 2303198 - Address already in use. 3024 * @throws { BusinessError } 2303199 - Cannot assign requested address. 3025 * @throws { BusinessError } 2303501 - SSL is null. 3026 * @throws { BusinessError } 2303502 - Error in tls reading. 3027 * @throws { BusinessError } 2303503 - Error in tls writing 3028 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 3029 * @throws { BusinessError } 2303506 - Error clearing tls connection. 3030 * @syscap SystemCapability.Communication.NetStack 3031 * @since 10 3032 */ 3033 listen(options: TLSConnectOptions): Promise<void>; 3034 3035 /** 3036 * Obtains the status of the TLSSocketServer connection. 3037 * @param { AsyncCallback<SocketStateBase> } callback - The callback of getState. 3038 * @throws { BusinessError } 401 - Parameter error. 3039 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3040 * @throws { BusinessError } 2300002 - System internal error. 3041 * @syscap SystemCapability.Communication.NetStack 3042 * @since 10 3043 */ 3044 getState(callback: AsyncCallback<SocketStateBase>): void; 3045 3046 /** 3047 * Obtains the status of the TLSSocketServer connection. 3048 * @returns { Promise<SocketStateBase> } The promise returned by the function. 3049 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3050 * @throws { BusinessError } 2300002 - System internal error. 3051 * @syscap SystemCapability.Communication.NetStack 3052 * @since 10 3053 */ 3054 getState(): Promise<SocketStateBase>; 3055 3056 /** 3057 * Sets other attributes of the TLSSocketServer connection. 3058 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 3059 * @param { AsyncCallback<void> } callback - The callback of setExtraOptions. 3060 * @throws { BusinessError } 401 - Parameter error. 3061 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3062 * @throws { BusinessError } 2300002 - System internal error. 3063 * @syscap SystemCapability.Communication.NetStack 3064 * @since 10 3065 */ 3066 setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void; 3067 3068 /** 3069 * Sets other attributes of the TLSSocketServer connection. 3070 * @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}. 3071 * @returns { Promise<void> } The promise returned by the function. 3072 * @throws { BusinessError } 401 - Parameter error. 3073 * @throws { BusinessError } 2303188 - Socket operation on non-socket. 3074 * @throws { BusinessError } 2300002 - System internal error. 3075 * @syscap SystemCapability.Communication.NetStack 3076 * @since 10 3077 */ 3078 setExtraOptions(options: TCPExtraOptions): Promise<void>; 3079 3080 /** 3081 * Returns an object representing a local certificate. 3082 * @param { AsyncCallback<X509CertRawData> } callback - The callback of getCertificate. 3083 * @throws { BusinessError } 401 - Parameter error. 3084 * @throws { BusinessError } 2303501 - SSL is null. 3085 * @throws { BusinessError } 2303504 - Error looking up x509 3086 * @throws { BusinessError } 2300002 - System internal error. 3087 * @syscap SystemCapability.Communication.NetStack 3088 * @since 10 3089 */ 3090 getCertificate(callback: AsyncCallback<X509CertRawData>): void; 3091 3092 /** 3093 * Returns an object representing a local certificate. 3094 * @returns { Promise<X509CertRawData> } The promise returned by the function. 3095 * @throws { BusinessError } 2303501 - SSL is null. 3096 * @throws { BusinessError } 2303504 - Error looking up x509 3097 * @throws { BusinessError } 2300002 - System internal error. 3098 * @syscap SystemCapability.Communication.NetStack 3099 * @since 10 3100 */ 3101 getCertificate(): Promise<X509CertRawData>; 3102 3103 /** 3104 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3105 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3106 * Server sockets or disconnected client sockets will return a value of null. 3107 * @param { AsyncCallback<string> } callback - The callback of getProtocol. 3108 * @throws { BusinessError } 401 - Parameter error. 3109 * @throws { BusinessError } 2303501 - SSL is null. 3110 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 3111 * @throws { BusinessError } 2300002 - System internal error. 3112 * @syscap SystemCapability.Communication.NetStack 3113 * @since 10 3114 */ 3115 getProtocol(callback: AsyncCallback<string>): void; 3116 3117 /** 3118 * Returns a string containing the negotiated SSL/TLS protocol version of the current connection. 3119 * For connected sockets that have not completed the handshake process, the value 'unknown' will be returned. 3120 * Server sockets or disconnected client sockets will return a value of null. 3121 * @returns { Promise<string> } The promise returned by the function. 3122 * @throws { BusinessError } 2303501 - SSL is null. 3123 * @throws { BusinessError } 2303505 - Error occurred in the tls system call. 3124 * @throws { BusinessError } 2300002 - System internal error. 3125 * @syscap SystemCapability.Communication.NetStack 3126 * @since 10 3127 */ 3128 getProtocol(): Promise<string>; 3129 3130 /** 3131 * Listens for connect events of the TLSSocketServer connection. 3132 * @param { 'connect' } type - Indicates Event name. 3133 * @param { Callback<TLSSocketConnection> } callback - The callback of on. 3134 * @throws { BusinessError } 401 - Parameter error. 3135 * @syscap SystemCapability.Communication.NetStack 3136 * @since 10 3137 */ 3138 on(type: 'connect', callback: Callback<TLSSocketConnection>): void; 3139 3140 /** 3141 * Cancels listening for connect events of the TLSSocketServer connection. 3142 * @param { 'connect' } type - Indicates Event name. 3143 * @param { Callback<TLSSocketConnection> } callback - The callback of off. 3144 * @throws { BusinessError } 401 - Parameter error. 3145 * @syscap SystemCapability.Communication.NetStack 3146 * @since 10 3147 */ 3148 off(type: 'connect', callback?: Callback<TLSSocketConnection>): void; 3149 3150 /** 3151 * Listens for error events of the TLSSocketServer connection. 3152 * @param { 'error' } type - Indicates Event name. 3153 * @param { ErrorCallback } callback - The callback of on. 3154 * @throws { BusinessError } 401 - Parameter error. 3155 * @syscap SystemCapability.Communication.NetStack 3156 * @since 10 3157 */ 3158 on(type: 'error', callback: ErrorCallback): void; 3159 3160 /** 3161 * Cancels listening for error events of the TLSSocketServer connection. 3162 * @param { 'error' } type - Indicates Event name. 3163 * @param { ErrorCallback } callback - The callback of off. 3164 * @throws { BusinessError } 401 - Parameter error. 3165 * @syscap SystemCapability.Communication.NetStack 3166 * @since 10 3167 */ 3168 off(type: 'error', callback?: ErrorCallback): void; 3169 } 3170} 3171 3172export default socket; 3173