1 Star 0 Fork 4K

Feng Lin/interface_sdk-js

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
@ohos.net.socket.d.ts 184.10 KB
Copy Edit Raw Blame History
openharmony_ci authored 2024-07-22 15:23 +08:00 . !12317 TLSSocket新增skipRemoteValidation
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @kit NetworkKit
*/
import type { AsyncCallback, Callback, ErrorCallback } from './@ohos.base';
import connection from "./@ohos.net.connection";
import type cert from './@ohos.security.cert';
/**
* Provides TCP and UDP Socket APIs.
* @namespace socket
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Provides TCP and UDP Socket APIs.
* @namespace socket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
declare namespace socket {
export import NetAddress = connection.NetAddress;
/**
* Deposit certificate
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Deposit certificate
* @typedef { cert.EncodingBlob }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export type X509CertRawData = cert.EncodingBlob;
/**
* Creates a UDPSocket object.
* @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Creates a UDPSocket object.
* @returns { UDPSocket } the UDPSocket of the constructUDPSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
function constructUDPSocketInstance(): UDPSocket;
/**
* Creates a MulticastSocket object.
* @returns { MulticastSocket } the MulticastSocket of the constructMulticastSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Creates a MulticastSocket object.
* @returns { MulticastSocket } the MulticastSocket of the constructMulticastSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
function constructMulticastSocketInstance(): MulticastSocket;
/**
* Creates a TCPSocket object.
* @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Creates a TCPSocket object.
* @returns { TCPSocket } the TCPSocket of the constructTCPSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
function constructTCPSocketInstance(): TCPSocket;
/**
* Creates a TLSSocket object.
* @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Creates a TLSSocket object.
* @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
function constructTLSSocketInstance(): TLSSocket;
/**
* Creates a TLSSocket object with a TCPSocket object.
* @param { TCPSocket } tcpSocket - Parameter for creating a TLSSocket object.
* @returns { TLSSocket } the TLSSocket of the constructTLSSocketInstance.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303601 - Invalid socket FD.
* @throws { BusinessError } 2303602 - Socket is not connected.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
function constructTLSSocketInstance(tcpSocket: TCPSocket): TLSSocket;
/**
* Creates a TCPSocketServer object.
* @returns { TCPSocketServer } the TCPSocketServer of the constructTCPSocketServerInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
function constructTCPSocketServerInstance(): TCPSocketServer;
/**
* Creates a TLSSocketServer object.
* @returns { TLSSocketServer } the TLSSocketServer of the constructTLSSocketServerInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
function constructTLSSocketServerInstance(): TLSSocketServer;
/**
* Creates a LocalSocket object.
* @returns { LocalSocket } the LocalSocket of the constructLocalSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Creates a LocalSocket object.
* @returns { LocalSocket } the LocalSocket of the constructLocalSocketInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
function constructLocalSocketInstance(): LocalSocket;
/**
* Creates a LocalSocketServer object.
* @returns { LocalSocketServer } the LocalSocketServer of the constructLocalSocketServerInstance.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Creates a LocalSocketServer object.
* @returns { LocalSocketServer } the LocalSocketServer of the constructLocalSocketServerInstance.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
function constructLocalSocketServerInstance(): LocalSocketServer;
/**
* Defines the parameters for sending data over the UDPSocket connection.
* @interface UDPSendOptions
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines the parameters for sending data over the UDPSocket connection.
* @interface UDPSendOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface UDPSendOptions {
/**
* Data to send.
* @type {string | ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Data to send.
* @type {string | ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
data: string | ArrayBuffer;
/**
* Destination address.
* @type {NetAddress}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Destination address.
* @type {NetAddress}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
address: NetAddress;
}
/**
* @interface ExtraOptionsBase
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* @interface ExtraOptionsBase
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface ExtraOptionsBase {
/**
* Size of the receive buffer, in MBS.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Size of the receive buffer, in MBS.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
receiveBufferSize?: number;
/**
* Size of the send buffer, in MBS.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Size of the send buffer, in MBS.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
sendBufferSize?: number;
/**
* Whether to reuse addresses. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether to reuse addresses. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
reuseAddress?: boolean;
/**
* Timeout duration of the UDPSocket connection, in milliseconds.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Timeout duration of the UDPSocket connection, in milliseconds.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
socketTimeout?: number;
}
/**
* Defines other properties of the UDPSocket connection.
* @interface UDPExtraOptions
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines other properties of the UDPSocket connection.
* @interface UDPExtraOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface UDPExtraOptions extends ExtraOptionsBase {
/**
* Whether to send broadcast messages. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether to send broadcast messages. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
broadcast?: boolean;
}
/**
* Defines the status of the socket connection.
* @interface SocketStateBase
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines the status of the socket connection.
* @interface SocketStateBase
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface SocketStateBase {
/**
* Whether the connection is in the bound state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether the connection is in the bound state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
isBound: boolean;
/**
* Whether the connection is in the closed state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether the connection is in the closed state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
isClose: boolean;
/**
* Whether the connection is in the connected state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether the connection is in the connected state.
* @type {boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
isConnected: boolean;
}
/**
* Defines information about the socket connection.
* @interface SocketRemoteInfo
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines information about the socket connection.
* @interface SocketRemoteInfo
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface SocketRemoteInfo {
/**
* Bound IP address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Bound IP address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
address: string;
/**
* Network protocol type. The options are as follows: IPv4, IPv6.
* @type {'IPv4' | 'IPv6'}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Network protocol type. The options are as follows: IPv4, IPv6.
* @type {'IPv4' | 'IPv6'}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
family: 'IPv4' | 'IPv6';
/**
* Port number. The value ranges from 0 to 65535.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Port number. The value ranges from 0 to 65535.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
port: number;
/**
* Length of the server response message, in bytes.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Length of the server response message, in bytes.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
size: number;
}
/**
* Defines the local socket connection information.
* @interface LocalSocketMessageInfo
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines the local socket connection information.
* @interface LocalSocketMessageInfo
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalSocketMessageInfo {
/**
* Message data.
* @type {ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Message data.
* @type {ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
message: ArrayBuffer;
/**
* Bound local socket address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Bound local socket address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
address: string;
/**
* Length of the message, in bytes.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Length of the message, in bytes.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
size: number;
}
/**
* Defines a local address.
* @interface LocalAddress
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines a local address.
* @interface LocalAddress
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalAddress {
/**
* LocalAddress address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* LocalAddress address.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
address: string;
}
/**
* Defines LocalSocket connection parameters.
* @interface LocalConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines LocalSocket connection parameters.
* @interface LocalConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalConnectOptions {
/**
* Bound Local address.
* @type {LocalAddress}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Bound Local address.
* @type {LocalAddress}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
address: LocalAddress;
/**
* Timeout duration of the LocalSocket connection, in milliseconds.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Timeout duration of the LocalSocket connection, in milliseconds.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
timeout?: number;
}
/**
* Defines the parameters for sending data over the LocalSocket connection.
* @interface LocalSendOptions
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines the parameters for sending data over the LocalSocket connection.
* @interface LocalSendOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalSendOptions {
/**
* Data to send.
* @type {string | ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Data to send.
* @type {string | ArrayBuffer}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
data: string | ArrayBuffer;
/**
* Character encoding format.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Character encoding format.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
encoding?: string;
}
/**
* Defines a UDPSocket connection.
* @interface UDPSocket
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines a UDPSocket connection.
* @interface UDPSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface UDPSocket {
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress, callback: AsyncCallback<void>): void;
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress): Promise<void>;
/**
* Obtains the local address of a UDPSocket connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Sends data over a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sends data over a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
send(options: UDPSendOptions, callback: AsyncCallback<void>): void;
/**
* Sends data over a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sends data over a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPSendOptions } options - Optional parameters {@link UDPSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
send(options: UDPSendOptions): Promise<void>;
/**
* Closes a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Closes a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(callback: AsyncCallback<void>): void;
/**
* Closes a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Closes a UDPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(): Promise<void>;
/**
* Obtains the status of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the status of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(callback: AsyncCallback<SocketStateBase>): void;
/**
* Obtains the status of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the status of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(): Promise<SocketStateBase>;
/**
* Sets other attributes of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
* @param { AsyncCallback<void> }callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets other attributes of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
* @param { AsyncCallback<void> }callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback<void>): void;
/**
* Sets other attributes of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets other attributes of the UDPSocket connection.
* @permission ohos.permission.INTERNET
* @param { UDPExtraOptions } options - Optional parameters {@link UDPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: UDPExtraOptions): Promise<void>;
/**
* Listens for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Listens for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
on(type: 'message', callback: Callback<SocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for message receiving events of the UDPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
/**
* Listens for data packet message events or close events of the UDPSocket connection.
* @param { 'listening' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for data packet message events or close events of the UDPSocket connection.
* @param { 'listening' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'listening' | 'close', callback: Callback<void>): void;
/**
* Cancels listening for data packet message events or close events of the UDPSocket connection.
* @param { 'listening' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for data packet message events or close events of the UDPSocket connection.
* @param { 'listening' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'listening' | 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the UDPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for error events of the UDPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the UDPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for error events of the UDPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines a UDP MulticastSocket connection.
* @interface MulticastSocket
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines a UDP MulticastSocket connection.
* @interface MulticastSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface MulticastSocket extends UDPSocket {
/**
* Add the socket to the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @param { AsyncCallback<void> } callback - The callback of addMembership.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Add the socket to the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @param { AsyncCallback<void> } callback - The callback of addMembership.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
addMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void;
/**
* Add the socket to the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Add the socket to the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
addMembership(multicastAddress: NetAddress): Promise<void>;
/**
* Drop the socket from the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @param { AsyncCallback<void> } callback - The callback of dropMembership.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Drop the socket from the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @param { AsyncCallback<void> } callback - The callback of dropMembership.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
dropMembership(multicastAddress: NetAddress, callback: AsyncCallback<void>): void;
/**
* Drop the socket from the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Drop the socket from the multicast group.
* @permission ohos.permission.INTERNET
* @param { NetAddress } multicastAddress - Multicast address information. {@link NetAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @throws { BusinessError } 2301098 - Address in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
dropMembership(multicastAddress: NetAddress): Promise<void>;
/**
* Set the TTL value for socket multicast packets.
* @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
* @param { AsyncCallback<void> } callback - The callback of setMulticastTTL.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Set the TTL value for socket multicast packets.
* @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
* @param { AsyncCallback<void> } callback - The callback of setMulticastTTL.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setMulticastTTL(ttl: number, callback: AsyncCallback<void>): void;
/**
* Set the TTL value for socket multicast packet.
* @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Set the TTL value for socket multicast packet.
* @param { number } ttl - The TTL value to set. Valid range is typically 0 to 255.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setMulticastTTL(ttl: number): Promise<void>;
/**
* Get the TTL value of socket multicast packet.
* @param { AsyncCallback<number> } callback - The callback of getMulticastTTL.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Get the TTL value of socket multicast packet.
* @param { AsyncCallback<number> } callback - The callback of getMulticastTTL.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getMulticastTTL(callback: AsyncCallback<number>): void;
/**
* Get the TTL value of socket multicast packet.
* @returns { Promise<number> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Get the TTL value of socket multicast packet.
* @returns { Promise<number> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getMulticastTTL(): Promise<number>;
/**
* Set the loopback mode for the socket.
* @param { boolean } flag - Whether to enable loopback mode.
* @param { AsyncCallback<void> } callback - The callback of setLoopbackMode.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Set the loopback mode for the socket.
* @param { boolean } flag - Whether to enable loopback mode.
* @param { AsyncCallback<void> } callback - The callback of setLoopbackMode.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setLoopbackMode(flag: boolean, callback: AsyncCallback<void>): void;
/**
* Set the loopback mode for the socket.
* @param { boolean } flag - Whether to enable loopback mode.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Set the loopback mode for the socket.
* @param { boolean } flag - Whether to enable loopback mode.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setLoopbackMode(flag: boolean): Promise<void>;
/**
* Get the loopback mode of the socket.
* @param { AsyncCallback<boolean> } callback - The callback of getLoopbackMode.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Get the loopback mode of the socket.
* @param { AsyncCallback<boolean> } callback - The callback of getLoopbackMode.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getLoopbackMode(callback: AsyncCallback<boolean>): void;
/**
* Get the loopback mode of the socket.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Get the loopback mode of the socket.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301088 - Not a socket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getLoopbackMode(): Promise<boolean>;
}
/**
* Defines a LocalSocket connection.
* @interface LocalSocket
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines a LocalSocket connection.
* @interface LocalSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalSocket {
/**
* Binds the Local address.
* @param { LocalAddress } address - Destination address. {@link LocalAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301098 - Address already in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Binds the Local address.
* @param { LocalAddress } address - Destination address. {@link LocalAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301098 - Address already in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
bind(address: LocalAddress): Promise<void>;
/**
* Sets up a connection to the specified Local address .
* @param { LocalConnectOptions } options - Optional parameters {@link LocalConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301111 - Connection refused.
* @throws { BusinessError } 2301099 - Cannot assign requested address.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Sets up a connection to the specified Local address .
* @param { LocalConnectOptions } options - Optional parameters {@link LocalConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301111 - Connection refused.
* @throws { BusinessError } 2301099 - Cannot assign requested address.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
connect(options: LocalConnectOptions): Promise<void>;
/**
* Sends data over a LocalSocket connection.
* @param { LocalSendOptions } options - Optional parameters {@link LocalSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301011 - Operation would block.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Sends data over a LocalSocket connection.
* @param { LocalSendOptions } options - Optional parameters {@link LocalSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301011 - Operation would block.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
send(options: LocalSendOptions): Promise<void>;
/**
* Closes a LocalSocket connection.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Closes a LocalSocket connection.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
close(): Promise<void>;
/**
* Obtains the status of the LocalSocket connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Obtains the status of the LocalSocket connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getState(): Promise<SocketStateBase>;
/**
* Obtains the file descriptor of the LocalSocket connection.
* @returns { Promise<number> } The promise returns the file descriptor of the LocalSocket connection.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Obtains the file descriptor of the LocalSocket connection.
* @returns { Promise<number> } The promise returns the file descriptor of the LocalSocket connection.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getSocketFd(): Promise<number>;
/**
* Sets other attributes of the LocalSocket connection.
* @param { ExtraOptionsBase } options - Optional parameters {@link ExtraOptionsBase}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Sets other attributes of the LocalSocket connection.
* @param { ExtraOptionsBase } options - Optional parameters {@link ExtraOptionsBase}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setExtraOptions(options: ExtraOptionsBase): Promise<void>;
/**
* Gets other attributes of the LocalSocket connection.
* @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Gets other attributes of the LocalSocket connection.
* @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getExtraOptions(): Promise<ExtraOptionsBase>;
/**
* Obtains the local address of a LocalSocket connection.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<string>;
/**
* Listens for message receiving events of the LocalSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for message receiving events of the LocalSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'message', callback: Callback<LocalSocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the LocalSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for message receiving events of the LocalSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'message', callback?: Callback<LocalSocketMessageInfo>): void;
/**
* Listens for connection events of the LocalSocket connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for connection events of the LocalSocket connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'connect', callback: Callback<void>): void;
/**
* Cancels listening for connection events of the LocalSocket connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for connection events of the LocalSocket connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'connect', callback?: Callback<void>): void;
/**
* Listens for close events of the LocalSocket connection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for close events of the LocalSocket connection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'close', callback: Callback<void>): void;
/**
* Cancels listening for close events of the LocalSocket connection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for close events of the LocalSocket connection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the LocalSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for error events of the LocalSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the LocalSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for error events of the LocalSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines the connection of the LocalSocket client and server.
* @interface LocalSocketConnection
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines the connection of the LocalSocket client and server.
* @interface LocalSocketConnection
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalSocketConnection {
/**
* The id of a client connects to the LocalSocketServer.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* The id of a client connects to the LocalSocketServer.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
clientId: number;
/**
* Sends data over a LocalSocketServer connection to client.
* @param { LocalSendOptions } options - Parameters for sending data {@link LocalSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301011 - Operation would block.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Sends data over a LocalSocketServer connection to client.
* @param { LocalSendOptions } options - Parameters for sending data {@link LocalSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301011 - Operation would block.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
send(options: LocalSendOptions): Promise<void>;
/**
* Closes a LocalSocket client connection.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Closes a LocalSocket client connection.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
close(): Promise<void>;
/**
* Obtains the local address of a LocalSocket client connection.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<string>;
/**
* Listens for message receiving events of the LocalSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for message receiving events of the LocalSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'message', callback: Callback<LocalSocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the LocalSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for message receiving events of the LocalSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<LocalSocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'message', callback?: Callback<LocalSocketMessageInfo>): void;
/**
* Listens for close events of the LocalSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for close events of the LocalSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'close', callback: Callback<void>): void;
/**
* Cancels listening for close events of the LocalSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for close events of the LocalSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the LocalSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for error events of the LocalSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the LocalSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for error events of the LocalSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines a LocalSocket server connection.
* @interface LocalSocketServer
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Defines a LocalSocket server connection.
* @interface LocalSocketServer
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface LocalSocketServer {
/**
* Binds the Local address.
* <p>Listens for a LocalSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @param { LocalAddress } address - Network address information {@link LocalAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301098 - Address already in use.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Binds the Local address.
* <p>Listens for a LocalSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @param { LocalAddress } address - Network address information {@link LocalAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2301013 - Insufficient permissions.
* @throws { BusinessError } 2301022 - Invalid argument.
* @throws { BusinessError } 2301098 - Address already in use.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
listen(address: LocalAddress): Promise<void>;
/**
* Obtains the status of the LocalSocketServer connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Obtains the status of the LocalSocketServer connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getState(): Promise<SocketStateBase>;
/**
* Sets other attributes of the LocalSocketServer connection.
* @param { ExtraOptionsBase } options - Parameters of the attributes {@link ExtraOptionsBase}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Sets other attributes of the LocalSocketServer connection.
* @param { ExtraOptionsBase } options - Parameters of the attributes {@link ExtraOptionsBase}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
setExtraOptions(options: ExtraOptionsBase): Promise<void>;
/**
* Gets other attributes of the LocalSocket connection.
* @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Gets other attributes of the LocalSocket connection.
* @returns { Promise<ExtraOptionsBase> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
getExtraOptions(): Promise<ExtraOptionsBase>;
/**
* Obtains the local address of the LocalSocketServer connection.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<string>;
/**
* Listens for connect events of the LocalSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<LocalSocketConnection> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for connect events of the LocalSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<LocalSocketConnection> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'connect', callback: Callback<LocalSocketConnection>): void;
/**
* Cancels listening for connect events of the LocalSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<LocalSocketConnection> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for connect events of the LocalSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<LocalSocketConnection> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'connect', callback?: Callback<LocalSocketConnection>): void;
/**
* Listens for error events of the LocalSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for error events of the LocalSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the LocalSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for error events of the LocalSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines TCPSocket connection parameters.
* @interface TCPConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines TCPSocket connection parameters.
* @interface TCPConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TCPConnectOptions {
/**
* Bound IP address and port number.
* @type { NetAddress }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Bound IP address and port number.
* @type { NetAddress }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
address: NetAddress;
/**
* Timeout duration of the TCPSocket connection, in milliseconds.
* @type { ?number }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Timeout duration of the TCPSocket connection, in milliseconds.
* @type { ?number }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
timeout?: number;
}
/**
* Defines the parameters for sending data over the TCPSocket connection.
* @interface TCPSendOptions
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines the parameters for sending data over the TCPSocket connection.
* @interface TCPSendOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TCPSendOptions {
/**
* Data to send.
* @type { string | ArrayBuffer }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Data to send.
* @type { string | ArrayBuffer }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
data: string | ArrayBuffer;
/**
* Character encoding format.
* @type { ?string }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Character encoding format.
* @type { ?string }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
encoding?: string;
}
/**
* Defines other properties of the TCPSocket connection.
* @interface TCPExtraOptions
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines other properties of the TCPSocket connection.
* @interface TCPExtraOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TCPExtraOptions extends ExtraOptionsBase {
/**
* Whether to keep the connection alive. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether to keep the connection alive. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
keepAlive?: boolean;
/**
* Whether to enable OOBInline. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether to enable OOBInline. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
OOBInline?: boolean;
/**
* Whether to enable no-delay on the TCPSocket connection. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Whether to enable no-delay on the TCPSocket connection. The default value is false.
* @type { ?boolean }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
TCPNoDelay?: boolean;
/**
* Socket linger.
* @type { ?object }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 7
*/
/**
* Socket linger.
* @type { ?object }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
socketLinger?: { on: boolean, linger: number };
}
/**
* Defines a TCPSocket connection.
* @interface TCPSocket
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Defines a TCPSocket connection.
* @interface TCPSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TCPSocket {
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - Return the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress, callback: AsyncCallback<void>): void;
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress): Promise<void>;
/**
* Sets up a connection to the specified IP address and port number.
* @permission ohos.permission.INTERNET
* @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
* @param { AsyncCallback<void> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets up a connection to the specified IP address and port number.
* @permission ohos.permission.INTERNET
* @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
* @param { AsyncCallback<void> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
connect(options: TCPConnectOptions, callback: AsyncCallback<void>): void;
/**
* Sets up a connection to the specified IP address and port number.
* @permission ohos.permission.INTERNET
* @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets up a connection to the specified IP address and port number.
* @permission ohos.permission.INTERNET
* @param { TCPConnectOptions } options - Optional parameters {@link TCPConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
connect(options: TCPConnectOptions): Promise<void>;
/**
* Sends data over a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sends data over a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
send(options: TCPSendOptions, callback: AsyncCallback<void>): void;
/**
* Sends data over a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sends data over a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Optional parameters {@link TCPSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
send(options: TCPSendOptions): Promise<void>;
/**
* Closes a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Closes a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(callback: AsyncCallback<void>): void;
/**
* Closes a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Closes a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(): Promise<void>;
/**
* Obtains the peer address of a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress}
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the peer address of a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress. {@link NetAddress}
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
/**
* Obtains the peer address of a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the peer address of a TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteAddress(): Promise<NetAddress>;
/**
* Obtains the status of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the status of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState. {@link SocketStateBase}
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(callback: AsyncCallback<SocketStateBase>): void;
/**
* Obtains the status of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Obtains the status of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(): Promise<SocketStateBase>;
/**
* Obtains the file descriptor of the TCPSocket connection.
* @param { AsyncCallback<number> } callback - The callback returns the file descriptor of the TCPSocket connection.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getSocketFd(callback: AsyncCallback<number>): void;
/**
* Obtains the file descriptor of the TCPSocket connection.
* @returns { Promise<number> } The promise returns the file descriptor of the TCPSocket connection.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getSocketFd(): Promise<number>;
/**
* Sets other attributes of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets other attributes of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
/**
* Sets other attributes of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Sets other attributes of the TCPSocket connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: TCPExtraOptions): Promise<void>;
/**
* Obtains the local address of a TCPSocket connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for message receiving events of the TCPSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for message receiving events of the TCPSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Listens for message receiving events of the TCPSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
on(type: 'message', callback: Callback<SocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the TCPSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for message receiving events of the TCPSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for message receiving events of the TCPSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
/**
* Listens for connection or close events of the TCPSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for connection or close events of the TCPSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'connect' | 'close', callback: Callback<void>): void;
/**
* Cancels listening for connection or close events of the TCPSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for connection or close events of the TCPSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'connect' | 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the TCPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Listens for error events of the TCPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TCPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 7
*/
/**
* Cancels listening for error events of the TCPSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines a TLSSocket connection.
* @interface TLSSocket
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Defines a TLSSocket connection.
* @interface TLSSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TLSSocket {
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @param { AsyncCallback<void> } callback - the callback of bind.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress, callback: AsyncCallback<void>): void;
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Binds the IP address and port number. The port number can be specified or randomly allocated by the system.
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Destination address. {@link NetAddress}
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
bind(address: NetAddress): Promise<void>;
/**
* Obtains the peer address of a TLSSocket connection.
* @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Obtains the peer address of a TLSSocket connection.
* @param { AsyncCallback<NetAddress> } callback - the callback of getRemoteAddress.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
/**
* Obtains the peer address of a TLSSocket connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Obtains the peer address of a TLSSocket connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteAddress(): Promise<NetAddress>;
/**
* Obtains the status of the TLSSocket connection.
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Obtains the status of the TLSSocket connection.
* @param { AsyncCallback<SocketStateBase> } callback - the callback of getState.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(callback: AsyncCallback<SocketStateBase>): void;
/**
* Obtains the status of the TLSSocket connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Obtains the status of the TLSSocket connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getState(): Promise<SocketStateBase>;
/**
* Sets other attributes of the TLSSocket connection.
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sets other attributes of the TLSSocket connection.
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - the callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
/**
* Sets other attributes of the TLSSocket connection.
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sets other attributes of the TLSSocket connection.
* @param { TCPExtraOptions } options - Optional parameters {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
setExtraOptions(options: TCPExtraOptions): Promise<void>;
/**
* Obtains the local address of a TLSSocket connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for message receiving events of the TLSSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Listens for message receiving events of the TLSSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Listens for message receiving events of the TLSSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
on(type: 'message', callback: Callback<SocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the TLSSocket connection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Cancels listening for message receiving events of the TLSSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for message receiving events of the TLSSocket connection.
* @param { 'message' } type Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
/**
* Listens for connection or close events of the TLSSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param {Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Listens for connection or close events of the TLSSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param {Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'connect' | 'close', callback: Callback<void>): void;
/**
* Cancels listening for connection or close events of the TLSSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param {Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Cancels listening for connection or close events of the TLSSocket connection.
* @param { 'connect' | 'close' } type - Indicates Event name.
* @param {Callback<void> } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'connect' | 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the TLSSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Listens for error events of the TLSSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TLSSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Cancels listening for error events of the TLSSocket connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - the callback used to return the result.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
/**
* Returns an object representing a local certificate.
* @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns an object representing a local certificate.
* @param { AsyncCallback<X509CertRawData> } callback - the callback of getCertificate.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getCertificate(callback: AsyncCallback<X509CertRawData>): void;
/**
* Returns an object representing a local certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns an object representing a local certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getCertificate(): Promise<X509CertRawData>;
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @param { AsyncCallback<X509CertRawData> } callback - the callback of getRemoteCertificate.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void;
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* <p>an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getRemoteCertificate(): Promise<X509CertRawData>;
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @param { AsyncCallback<string> } callback - the callback of getProtocol.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @param { AsyncCallback<string> } callback - the callback of getProtocol.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getProtocol(callback: AsyncCallback<string>): void;
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getProtocol(): Promise<string>;
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @param { AsyncCallback<Array<string>> } callback - the callback of getCipherSuite.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getCipherSuite(callback: AsyncCallback<Array<string>>): void;
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @returns { Promise<Array<string>> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @returns { Promise<Array<string>> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getCipherSuite(): Promise<Array<string>>;
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @param { AsyncCallback<Array<string>> } callback - the callback of getSignatureAlgorithms.@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void;
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @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
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @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
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
getSignatureAlgorithms(): Promise<Array<string>>;
/**
* Sets up a connection to the specified IP address and port number.
* Only TCP is supported.
* @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
* @param { AsyncCallback<void> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303104 - Interrupted system call.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2303191 - Incorrect socket protocol type.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303210 - Connection timed out.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sets up a connection to the specified IP address and port number.
* Only TCP is supported.
* @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
* @param { AsyncCallback<void> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303104 - Interrupted system call.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2303191 - Incorrect socket protocol type.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303210 - Connection timed out.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
connect(options: TLSConnectOptions, callback: AsyncCallback<void>): void;
/**
* Sets up a connection to the specified IP address and port number.
* Only TCP is supported.
* @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303104 - Interrupted system call.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2303191 - Incorrect socket protocol type.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303210 - Connection timed out.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sets up a connection to the specified IP address and port number.
* Only TCP is supported.
* @param { TLSConnectOptions } options - Optional parameters {@link TLSConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303104 - Interrupted system call.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2303191 - Incorrect socket protocol type.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303210 - Connection timed out.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
connect(options: TLSConnectOptions): Promise<void>;
/**
* Sends data over a TLSSocket connection.
* @param { string } data - Parameters for sending data {@link string}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sends data over a TLSSocket connection.
* @param { string } data - Parameters for sending data {@link string}.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Sends data over a TLSSocket connection.
* @param { string | ArrayBuffer } data - Parameters for sending data.
* @param { AsyncCallback<void> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void;
/**
* Sends data over a TLSSocket connection.
* @param { string } data - Parameters for sending data {@link string}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Sends data over a TLSSocket connection.
* @param { string } data - Parameters for sending data {@link string}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Sends data over a TLSSocket connection.
* @param { string | ArrayBuffer } data - Parameters for sending data.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
send(data: string | ArrayBuffer): Promise<void>;
/**
* Closes a TLSSocket connection
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Closes a TLSSocket connection
* @param { AsyncCallback<void> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(callback: AsyncCallback<void>): void;
/**
* Closes a TLSSocket connection
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Closes a TLSSocket connection
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
close(): Promise<void>;
}
/**
* Defines TLS security options. The CA certificate is mandatory, and other parameters are optional.
* @interface TLSSecureOptions
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Defines TLS security options. The CA certificate is mandatory, and other parameters are optional.
* @interface TLSSecureOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TLSSecureOptions {
/**
* Certificate used to verify the identity of the server
* @type {string | Array<string>}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Certificate used to verify the identity of the server.
* @type {string | Array<string>}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Certificate used to verify the identity of the server, if it is not set, use system ca.
* @type {?(string | Array<string>)}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
ca?: string | Array<string>;
/**
* Certificate proving the identity of the client
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Certificate proving the identity of the client
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
cert?: string;
/**
* Private key of client certificate
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Private key of client certificate
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
key?: string;
/**
* Password of the private key
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Password of the private key
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
password?: string;
/**
* TLS protocol version
* @type {?Protocol | Array<Protocol>}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* TLS protocol version
* @type {?(Protocol | Array<Protocol>)}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
protocols?: Protocol | Array<Protocol>;
/**
* default is false, use local cipher.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* default is false, use local cipher.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
useRemoteCipherPrefer?: boolean;
/**
* <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc),
* Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P>
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* <P>Supported signature algorithms. This string can contain summary algorithms(SHA256,MD5,etc),Public key algorithm(RSA-PSS,ECDSA,etc),
* Combination of the two(For example 'RSA+SHA384') or TLS v1.3 Scheme name(For example rsa_pss_pss_sha512)</P>
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
signatureAlgorithms?: string;
/**
* Crypto suite specification
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Crypto suite specification
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
cipherSuite?: string;
/**
* Used to set up bidirectional authentication. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
isBidirectionalAuthentication?: boolean;
}
/**
* Defines TLS connection options.
* @interface TLSConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Defines TLS connection options.
* @interface TLSConnectOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export interface TLSConnectOptions {
/**
* Gateway address.
* @type {NetAddress}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Gateway address.
* @type {NetAddress}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
address: NetAddress;
/**
* Protocol http2TLS security related operations.
* @type {TLSSecureOptions}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Protocol http2TLS security related operations.
* @type {TLSSecureOptions}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
secureOptions: TLSSecureOptions;
/**
* Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2"
* @type {?Array<string>}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Application layer protocol negotiation extension, such as "spdy/1", "http/1.1", "h2"
* @type {?Array<string>}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
ALPNProtocols?: Array<string>;
/**
* Skip identity verification for remote servers. The default value is false.
* @type {?boolean}
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
skipRemoteValidation?: boolean;
}
/**
* Enumerates TLS protocol versions.
* @enum {string}
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Enumerates TLS protocol versions.
* @enum {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
export enum Protocol {
/**
* Use TLSv1.2 protocol for communication.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Use TLSv1.2 protocol for communication.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
TLSv12 = "TLSv1.2",
/**
* Use TLSv1.3 protocol for communication.
* @syscap SystemCapability.Communication.NetStack
* @since 9
*/
/**
* Use TLSv1.3 protocol for communication.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
TLSv13 = "TLSv1.3"
}
/**
* Defines the connection of the TCPSocket client and server.
* @interface TCPSocketConnection
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
export interface TCPSocketConnection {
/**
* The id of a client connects to the TCPSocketServer.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
clientId: number;
/**
* Sends data over a TCPSocketServer connection to client.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}.
* @param { AsyncCallback<void> } callback - The callback of send.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
send(options: TCPSendOptions, callback: AsyncCallback<void>): void;
/**
* Sends data over a TCPSocketServer connection to client.
* @permission ohos.permission.INTERNET
* @param { TCPSendOptions } options - Parameters for sending data {@link TCPSendOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
send(options: TCPSendOptions): Promise<void>;
/**
* Closes a TCPSocket client connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<void> } callback - The callback of close.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
close(callback: AsyncCallback<void>): void;
/**
* Closes a TCPSocket client connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
close(): Promise<void>;
/**
* Obtains the peer address of a TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
/**
* Obtains the peer address of a TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteAddress(): Promise<NetAddress>;
/**
* Obtains the local address of a TCPSocketServer connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Listens for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'message', callback: Callback<SocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Cancels listening for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for message receiving events of the TCPSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
/**
* Listens for close events of the TCPSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'close', callback: Callback<void>): void;
/**
* Cancels listening for close events of the TCPSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the TCPSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TCPSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines a TCPSocket server connection.
* @interface TCPSocketServer
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
export interface TCPSocketServer {
/**
* Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
* <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Network address information {@link NetAddress}.
* @param { AsyncCallback<void> } callback - The callback of listen.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
listen(address: NetAddress, callback: AsyncCallback<void>): void;
/**
* Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
* <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @permission ohos.permission.INTERNET
* @param { NetAddress } address - Network address information {@link NetAddress}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
listen(address: NetAddress): Promise<void>;
/**
* Obtains the status of the TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<SocketStateBase> } callback - The callback of getState.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getState(callback: AsyncCallback<SocketStateBase>): void;
/**
* Obtains the status of the TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getState(): Promise<SocketStateBase>;
/**
* Sets other attributes of the TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - The callback of setExtraOptions.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
/**
* Sets other attributes of the TCPSocketServer connection.
* @permission ohos.permission.INTERNET
* @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
setExtraOptions(options: TCPExtraOptions): Promise<void>;
/**
* Obtains the local address of a TCPSocketServer connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for connect events of the TCPSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<TCPSocketConnection> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'connect', callback: Callback<TCPSocketConnection>): void;
/**
* Cancels listening for connect events of the TCPSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<TCPSocketConnection> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'connect', callback?: Callback<TCPSocketConnection>): void;
/**
* Listens for error events of the TCPSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TCPSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines the connection of the TLSSocket client and server.
* @interface TLSSocketConnection
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
export interface TLSSocketConnection {
/**
* The id of a client connects to the TLSSocketServer.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
clientId: number;
/**
* Sends data over a TLSSocketServer connection to client.
* @param { string } data - Parameters for sending data.
* @param { AsyncCallback<void> } callback - The callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Sends data over a TLSSocketServer connection to client.
* @param { string | ArrayBuffer } data - Parameters for sending data.
* @param { AsyncCallback<void> } callback - The callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
send(data: string | ArrayBuffer, callback: AsyncCallback<void>): void;
/**
* Sends data over a TLSSocketServer connection to client.
* @param { string } data - Parameters for sending data.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Sends data over a TLSSocketServer connection to client.
* @param { string | ArrayBuffer } data - Parameters for sending data.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
send(data: string | ArrayBuffer): Promise<void>;
/**
* Closes a TLSSocket client connection.
* @param { AsyncCallback<void> } callback - The callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
close(callback: AsyncCallback<void>): void;
/**
* Closes a TLSSocket client connection.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
close(): Promise<void>;
/**
* Obtains the peer address of a TLSSocketServer connection.
* @param { AsyncCallback<NetAddress> } callback - The callback of getRemoteAddress.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteAddress(callback: AsyncCallback<NetAddress>): void;
/**
* Obtains the peer address of a TLSSocketServer connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteAddress(): Promise<NetAddress>;
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @param { AsyncCallback<X509CertRawData> } callback - The callback of getRemoteCertificate.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteCertificate(callback: AsyncCallback<X509CertRawData>): void;
/**
* <p>Returns an object representing the peer certificate. If the peer does not provide a certificate,
* an empty object will be returned. If the socket is destroyed, null is returned.</p>
* It only contains the peer's certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getRemoteCertificate(): Promise<X509CertRawData>;
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @param { AsyncCallback<Array<string>> } callback - The callback of getCipherSuite.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getCipherSuite(callback: AsyncCallback<Array<string>>): void;
/**
* Returns a list containing the negotiated cipher suite information.
* For example:{"TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"}
* @returns { Promise<Array<string>> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getCipherSuite(): Promise<Array<string>>;
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @param { AsyncCallback<Array<string>> } callback - The callback of getSignatureAlgorithms.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getSignatureAlgorithms(callback: AsyncCallback<Array<string>>): void;
/**
* <p>The list of signature algorithms shared between the server and the client,
* in descending order of priority.</p>
* @returns { Promise<Array<string>> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getSignatureAlgorithms(): Promise<Array<string>>;
/**
* Obtains the local address of a TLSSocketServer connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Listens for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Listens for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'message', callback: Callback<SocketMessageInfo>): void;
/**
* Cancels listening for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<{ message: ArrayBuffer, remoteInfo: SocketRemoteInfo }> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
/**
* Cancels listening for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for message receiving events of the TLSSocketConnection.
* @param { 'message' } type - Indicates Event name.
* @param { Callback<SocketMessageInfo> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'message', callback?: Callback<SocketMessageInfo>): void;
/**
* Listens for close events of the TLSSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'close', callback: Callback<void>): void;
/**
* Cancels listening for close events of the TLSSocketConnection.
* @param { 'close' } type - Indicates Event name.
* @param { Callback<void> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'close', callback?: Callback<void>): void;
/**
* Listens for error events of the TLSSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TLSSocketConnection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
/**
* Defines the socket connection information.
* @interface SocketMessageInfo
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
export interface SocketMessageInfo {
/**
* Receive the message event.
* @type { ArrayBuffer }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
message: ArrayBuffer;
/**
* Socket connection information.
* @type { SocketRemoteInfo }
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 11
*/
remoteInfo: SocketRemoteInfo;
}
/**
* Defines a TLSSocketServer server connection.
* @interface TLSSocketServer
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
export interface TLSSocketServer {
/**
* Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
* <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @permission ohos.permission.INTERNET
* @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}.
* @param { AsyncCallback<void> } callback - The callback of listen.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
listen(options: TLSConnectOptions, callback: AsyncCallback<void>): void;
/**
* Binds the IP address and port number, the port number can be specified or randomly allocated by the system.
* <p>Listens for a TCPSocket connection to be made to this socket and accepts it. This interface uses multiple threads
* for accept processing and uses poll multiplex to process client connections.</p>
* @permission ohos.permission.INTERNET
* @param { TLSConnectOptions } options - TLS connection options {@link TLSConnectOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2303109 - Bad file number.
* @throws { BusinessError } 2303111 - Resource temporarily unavailable. Try again.
* @throws { BusinessError } 2303198 - Address already in use.
* @throws { BusinessError } 2303199 - Cannot assign requested address.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303502 - An error occurred when reading data on the TLS socket.
* @throws { BusinessError } 2303503 - An error occurred when writing data on the TLS socket.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2303506 - Failed to close the TLS connection.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
listen(options: TLSConnectOptions): Promise<void>;
/**
* Obtains the status of the TLSSocketServer connection.
* @param { AsyncCallback<SocketStateBase> } callback - The callback of getState.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getState(callback: AsyncCallback<SocketStateBase>): void;
/**
* Obtains the status of the TLSSocketServer connection.
* @returns { Promise<SocketStateBase> } The promise returned by the function.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getState(): Promise<SocketStateBase>;
/**
* Sets other attributes of the TLSSocketServer connection.
* @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
* @param { AsyncCallback<void> } callback - The callback of setExtraOptions.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback<void>): void;
/**
* Sets other attributes of the TLSSocketServer connection.
* @param { TCPExtraOptions } options - Parameters of the attributes {@link TCPExtraOptions}.
* @returns { Promise<void> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
setExtraOptions(options: TCPExtraOptions): Promise<void>;
/**
* Returns an object representing a local certificate.
* @param { AsyncCallback<X509CertRawData> } callback - The callback of getCertificate.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getCertificate(callback: AsyncCallback<X509CertRawData>): void;
/**
* Returns an object representing a local certificate.
* @returns { Promise<X509CertRawData> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303504 - An error occurred when verifying the X.509 certificate.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getCertificate(): Promise<X509CertRawData>;
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @param { AsyncCallback<string> } callback - The callback of getProtocol.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getProtocol(callback: AsyncCallback<string>): void;
/**
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
* For connected sockets that have not completed the handshake process, the value 'unknown' will be returned.
* Server sockets or disconnected client sockets will return a value of null.
* @returns { Promise<string> } The promise returned by the function.
* @throws { BusinessError } 2303501 - SSL is null.
* @throws { BusinessError } 2303505 - An error occurred in the TLS system call.
* @throws { BusinessError } 2300002 - System internal error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
getProtocol(): Promise<string>;
/**
* Obtains the local address of the TLSSocketServer connection.
* @returns { Promise<NetAddress> } The promise returned by the function.
* @throws { BusinessError } 2300002 - System internal error.
* @throws { BusinessError } 2301009 - Bad file descriptor.
* @throws { BusinessError } 2303188 - Socket operation on non-socket.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
getLocalAddress(): Promise<NetAddress>;
/**
* Listens for connect events of the TLSSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<TLSSocketConnection> } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'connect', callback: Callback<TLSSocketConnection>): void;
/**
* Cancels listening for connect events of the TLSSocketServer connection.
* @param { 'connect' } type - Indicates Event name.
* @param { Callback<TLSSocketConnection> } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'connect', callback?: Callback<TLSSocketConnection>): void;
/**
* Listens for error events of the TLSSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of on.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for error events of the TLSSocketServer connection.
* @param { 'error' } type - Indicates Event name.
* @param { ErrorCallback } callback - The callback of off.
* @throws { BusinessError } 401 - Parameter error.
* @syscap SystemCapability.Communication.NetStack
* @since 10
*/
off(type: 'error', callback?: ErrorCallback): void;
}
}
export default socket;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lffl8796/interface_sdk-js.git
git@gitee.com:lffl8796/interface_sdk-js.git
lffl8796
interface_sdk-js
interface_sdk-js
master

Search