12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/net</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/net</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="ssl_toc" href="#ssl">SSL</a></li>
- <li><a class="reference" id="ssl-on-windows_toc" href="#ssl-on-windows">SSL on Windows</a></li>
- <li><a class="reference" id="examples_toc" href="#examples">Examples</a></li>
- <ul class="simple"><li><a class="reference" id="examples-connecting-to-a-server_toc" href="#examples-connecting-to-a-server">Connecting to a server</a></li>
- <li><a class="reference" id="examples-creating-a-server_toc" href="#examples-creating-a-server">Creating a server</a></li>
- </ul><li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#Certificate" title="Certificate = string">Certificate</a></li>
- <li><a class="reference" href="#IpAddress" title="IpAddress = object
- case family*: IpAddressFamily ## the type of the IP address (IPv4 or IPv6)
- of IpAddressFamily.IPv6:
- address_v6*: array[0 .. 15, uint8] ## Contains the IP address in bytes in
- ## case of IPv6
- of IpAddressFamily.IPv4:
- address_v4*: array[0 .. 3, uint8] ## Contains the IP address in bytes in
- ## case of IPv4">IpAddress</a></li>
- <li><a class="reference" href="#IpAddressFamily" title="IpAddressFamily {.pure.} = enum
- IPv6, ## IPv6 address
- IPv4 ## IPv4 address">IpAddressFamily</a></li>
- <li><a class="reference" href="#ReadLineResult" title="ReadLineResult = enum
- ReadFullLine, ReadPartialLine, ReadDisconnected, ReadNone">ReadLineResult</a></li>
- <li><a class="reference" href="#SOBool" title="SOBool = enum
- OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
- OptOOBInline, OptReuseAddr, OptReusePort, OptNoDelay">SOBool</a></li>
- <li><a class="reference" href="#Socket" title="Socket = ref SocketImpl">Socket</a></li>
- <li><a class="reference" href="#SocketFlag" title="SocketFlag {.pure.} = enum
- Peek, SafeDisconn ## Ensures disconnection exceptions (ECONNRESET, EPIPE etc) are not thrown.">SocketFlag</a></li>
- <li><a class="reference" href="#SocketImpl" title="SocketImpl = object
- when defineSsl:
- ## stores the last error on this socket">SocketImpl</a></li>
- <li><a class="reference" href="#SslAcceptResult" title="SslAcceptResult = enum
- AcceptNoClient = 0, AcceptNoHandshake, AcceptSuccess">SslAcceptResult</a></li>
- <li><a class="reference" href="#SslClientGetPskFunc" title="SslClientGetPskFunc = proc (hint: string): tuple[identity: string, psk: string]">SslClientGetPskFunc</a></li>
- <li><a class="reference" href="#SslContext" title="SslContext = ref object
- context*: SslCtx">SslContext</a></li>
- <li><a class="reference" href="#SslCVerifyMode" title="SslCVerifyMode = enum
- CVerifyNone, CVerifyPeer, CVerifyPeerUseEnvVars">SslCVerifyMode</a></li>
- <li><a class="reference" href="#SslError" title="SslError = object of CatchableError">SslError</a></li>
- <li><a class="reference" href="#SslHandshakeType" title="SslHandshakeType = enum
- handshakeAsClient, handshakeAsServer">SslHandshakeType</a></li>
- <li><a class="reference" href="#SslProtVersion" title="SslProtVersion = enum
- protSSLv2, protSSLv3, protTLSv1, protSSLv23">SslProtVersion</a></li>
- <li><a class="reference" href="#SslServerGetPskFunc" title="SslServerGetPskFunc = proc (identity: string): string">SslServerGetPskFunc</a></li>
- <li><a class="reference" href="#TimeoutError" title="TimeoutError = object of CatchableError">TimeoutError</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#BufferSize" title="BufferSize: int = 4000">BufferSize</a></li>
- <li><a class="reference" href="#MaxLineLength" title="MaxLineLength = 1000000">MaxLineLength</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">$
- <li><a class="reference" href="#%24%2CIpAddress" title="`$`(address: IpAddress): string">`$`(address: IpAddress): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">==
- <li><a class="reference" href="#%3D%3D%2CIpAddress%2CIpAddress" title="`==`(lhs, rhs: IpAddress): bool">`==`(lhs, rhs: IpAddress): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">accept
- <li><a class="reference" href="#accept%2CSocket%2C" title="accept(server: Socket; client: var owned(Socket); flags = {SafeDisconn};
- inheritable = defined(nimInheritHandles))">accept(server: Socket; client: var owned(Socket); flags = {SafeDisconn};
- inheritable = defined(nimInheritHandles))</a></li>
- </ul>
- <ul class="simple nested-toc-section">acceptAddr
- <li><a class="reference" href="#acceptAddr%2CSocket%2C%2Cstring" title="acceptAddr(server: Socket; client: var owned(Socket); address: var string;
- flags = {SafeDisconn}; inheritable = defined(nimInheritHandles))">acceptAddr(server: Socket; client: var owned(Socket); address: var string;
- flags = {SafeDisconn}; inheritable = defined(nimInheritHandles))</a></li>
- </ul>
- <ul class="simple nested-toc-section">bindAddr
- <li><a class="reference" href="#bindAddr%2CSocket%2Cstring" title="bindAddr(socket: Socket; port = Port(0); address = "")">bindAddr(socket: Socket; port = Port(0); address = "")</a></li>
- </ul>
- <ul class="simple nested-toc-section">bindUnix
- <li><a class="reference" href="#bindUnix%2CSocket%2Cstring" title="bindUnix(socket: Socket; path: string)">bindUnix(socket: Socket; path: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">clientGetPskFunc
- <li><a class="reference" href="#clientGetPskFunc%2CSslContext" title="clientGetPskFunc(ctx: SslContext): SslClientGetPskFunc">clientGetPskFunc(ctx: SslContext): SslClientGetPskFunc</a></li>
- </ul>
- <ul class="simple nested-toc-section">clientGetPskFunc=
- <li><a class="reference" href="#clientGetPskFunc%3D%2CSslContext%2CSslClientGetPskFunc" title="clientGetPskFunc=(ctx: SslContext; fun: SslClientGetPskFunc)">clientGetPskFunc=(ctx: SslContext; fun: SslClientGetPskFunc)</a></li>
- </ul>
- <ul class="simple nested-toc-section">close
- <li><a class="reference" href="#close%2CSocket" title="close(socket: Socket; flags = {SafeDisconn})">close(socket: Socket; flags = {SafeDisconn})</a></li>
- </ul>
- <ul class="simple nested-toc-section">connect
- <li><a class="reference" href="#connect%2CSocket%2Cstring" title="connect(socket: Socket; address: string; port = Port(0))">connect(socket: Socket; address: string; port = Port(0))</a></li>
- <li><a class="reference" href="#connect%2CSocket%2Cstring%2Cint" title="connect(socket: Socket; address: string; port = Port(0); timeout: int)">connect(socket: Socket; address: string; port = Port(0); timeout: int)</a></li>
- </ul>
- <ul class="simple nested-toc-section">connectUnix
- <li><a class="reference" href="#connectUnix%2CSocket%2Cstring" title="connectUnix(socket: Socket; path: string)">connectUnix(socket: Socket; path: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">destroyContext
- <li><a class="reference" href="#destroyContext%2CSslContext" title="destroyContext(ctx: SslContext)">destroyContext(ctx: SslContext)</a></li>
- </ul>
- <ul class="simple nested-toc-section">dial
- <li><a class="reference" href="#dial%2Cstring%2CPort" title="dial(address: string; port: Port; protocol = IPPROTO_TCP; buffered = true): owned(
- Socket)">dial(address: string; port: Port; protocol = IPPROTO_TCP; buffered = true): owned(
- Socket)</a></li>
- </ul>
- <ul class="simple nested-toc-section">fromSockAddr
- <li><a class="reference" href="#fromSockAddr%2C%2CSockLen%2CIpAddress%2CPort" title="fromSockAddr(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6;
- sl: SockLen; address: var IpAddress; port: var Port)">fromSockAddr(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6;
- sl: SockLen; address: var IpAddress; port: var Port)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getExtraData
- <li><a class="reference" href="#getExtraData%2CSslContext%2Cint" title="getExtraData(ctx: SslContext; index: int): RootRef">getExtraData(ctx: SslContext; index: int): RootRef</a></li>
- </ul>
- <ul class="simple nested-toc-section">getFd
- <li><a class="reference" href="#getFd%2CSocket" title="getFd(socket: Socket): SocketHandle">getFd(socket: Socket): SocketHandle</a></li>
- </ul>
- <ul class="simple nested-toc-section">getLocalAddr
- <li><a class="reference" href="#getLocalAddr%2CSocket" title="getLocalAddr(socket: Socket): (string, Port)">getLocalAddr(socket: Socket): (string, Port)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPeerAddr
- <li><a class="reference" href="#getPeerAddr%2CSocket" title="getPeerAddr(socket: Socket): (string, Port)">getPeerAddr(socket: Socket): (string, Port)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPeerCertificates
- <li><a class="reference" href="#getPeerCertificates%2CSocket" title="getPeerCertificates(socket: Socket): seq[Certificate]">getPeerCertificates(socket: Socket): seq[Certificate]</a></li>
- <li><a class="reference" href="#getPeerCertificates%2CSslPtr" title="getPeerCertificates(sslHandle: SslPtr): seq[Certificate]">getPeerCertificates(sslHandle: SslPtr): seq[Certificate]</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPrimaryIPAddr
- <li><a class="reference" href="#getPrimaryIPAddr" title="getPrimaryIPAddr(dest = parseIpAddress("8.8.8.8")): IpAddress">getPrimaryIPAddr(dest = parseIpAddress("8.8.8.8")): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPskIdentity
- <li><a class="reference" href="#getPskIdentity%2CSocket" title="getPskIdentity(socket: Socket): string">getPskIdentity(socket: Socket): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">getSocketError
- <li><a class="reference" href="#getSocketError%2CSocket" title="getSocketError(socket: Socket): OSErrorCode">getSocketError(socket: Socket): OSErrorCode</a></li>
- </ul>
- <ul class="simple nested-toc-section">getSockOpt
- <li><a class="reference" href="#getSockOpt%2CSocket%2CSOBool" title="getSockOpt(socket: Socket; opt: SOBool; level = SOL_SOCKET): bool">getSockOpt(socket: Socket; opt: SOBool; level = SOL_SOCKET): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">gotHandshake
- <li><a class="reference" href="#gotHandshake%2CSocket" title="gotHandshake(socket: Socket): bool">gotHandshake(socket: Socket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">hasDataBuffered
- <li><a class="reference" href="#hasDataBuffered%2CSocket" title="hasDataBuffered(s: Socket): bool">hasDataBuffered(s: Socket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">IPv4_any
- <li><a class="reference" href="#IPv4_any" title="IPv4_any(): IpAddress">IPv4_any(): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">IPv4_broadcast
- <li><a class="reference" href="#IPv4_broadcast" title="IPv4_broadcast(): IpAddress">IPv4_broadcast(): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">IPv4_loopback
- <li><a class="reference" href="#IPv4_loopback" title="IPv4_loopback(): IpAddress">IPv4_loopback(): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">IPv6_any
- <li><a class="reference" href="#IPv6_any" title="IPv6_any(): IpAddress">IPv6_any(): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">IPv6_loopback
- <li><a class="reference" href="#IPv6_loopback" title="IPv6_loopback(): IpAddress">IPv6_loopback(): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">isDisconnectionError
- <li><a class="reference" href="#isDisconnectionError%2Cset%5BSocketFlag%5D%2COSErrorCode" title="isDisconnectionError(flags: set[SocketFlag]; lastError: OSErrorCode): bool">isDisconnectionError(flags: set[SocketFlag]; lastError: OSErrorCode): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">isIpAddress
- <li><a class="reference" href="#isIpAddress%2Cstring" title="isIpAddress(addressStr: string): bool">isIpAddress(addressStr: string): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">isSsl
- <li><a class="reference" href="#isSsl%2CSocket" title="isSsl(socket: Socket): bool">isSsl(socket: Socket): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">listen
- <li><a class="reference" href="#listen%2CSocket" title="listen(socket: Socket; backlog = SOMAXCONN)">listen(socket: Socket; backlog = SOMAXCONN)</a></li>
- </ul>
- <ul class="simple nested-toc-section">newContext
- <li><a class="reference" href="#newContext%2Cstring%2Cstring%2Cstring%2Cstring" title="newContext(protVersion = protSSLv23; verifyMode = CVerifyPeer; certFile = "";
- keyFile = ""; cipherList = CiphersIntermediate; caDir = "";
- caFile = ""; ciphersuites = CiphersModern): SslContext">newContext(protVersion = protSSLv23; verifyMode = CVerifyPeer; certFile = "";
- keyFile = ""; cipherList = CiphersIntermediate; caDir = "";
- caFile = ""; ciphersuites = CiphersModern): SslContext</a></li>
- </ul>
- <ul class="simple nested-toc-section">newSocket
- <li><a class="reference" href="#newSocket%2Ccint%2Ccint%2Ccint" title="newSocket(domain, sockType, protocol: cint; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(Socket)">newSocket(domain, sockType, protocol: cint; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(Socket)</a></li>
- <li><a class="reference" href="#newSocket%2CDomain%2CSockType%2CProtocol" title="newSocket(domain: Domain = AF_INET; sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(Socket)">newSocket(domain: Domain = AF_INET; sockType: SockType = SOCK_STREAM;
- protocol: Protocol = IPPROTO_TCP; buffered = true;
- inheritable = defined(nimInheritHandles)): owned(Socket)</a></li>
- <li><a class="reference" href="#newSocket%2CSocketHandle%2CDomain%2CSockType%2CProtocol" title="newSocket(fd: SocketHandle; domain: Domain = AF_INET;
- sockType: SockType = SOCK_STREAM; protocol: Protocol = IPPROTO_TCP;
- buffered = true): owned(Socket)">newSocket(fd: SocketHandle; domain: Domain = AF_INET;
- sockType: SockType = SOCK_STREAM; protocol: Protocol = IPPROTO_TCP;
- buffered = true): owned(Socket)</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseIpAddress
- <li><a class="reference" href="#parseIpAddress%2Cstring" title="parseIpAddress(addressStr: string): IpAddress">parseIpAddress(addressStr: string): IpAddress</a></li>
- </ul>
- <ul class="simple nested-toc-section">pskIdentityHint=
- <li><a class="reference" href="#pskIdentityHint%3D%2CSslContext%2Cstring" title="pskIdentityHint=(ctx: SslContext; hint: string)">pskIdentityHint=(ctx: SslContext; hint: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">raiseSSLError
- <li><a class="reference" href="#raiseSSLError%2Cstring" title="raiseSSLError(s = "")">raiseSSLError(s = "")</a></li>
- </ul>
- <ul class="simple nested-toc-section">readLine
- <li><a class="reference" href="#readLine%2CSocket%2Cstring%2Cint" title="readLine(socket: Socket; line: var string; timeout = -1; flags = {SafeDisconn};
- maxLength = MaxLineLength)">readLine(socket: Socket; line: var string; timeout = -1; flags = {SafeDisconn};
- maxLength = MaxLineLength)</a></li>
- </ul>
- <ul class="simple nested-toc-section">recv
- <li><a class="reference" href="#recv%2CSocket%2Cpointer%2Cint" title="recv(socket: Socket; data: pointer; size: int): int">recv(socket: Socket; data: pointer; size: int): int</a></li>
- <li><a class="reference" href="#recv%2CSocket%2Cpointer%2Cint%2Cint" title="recv(socket: Socket; data: pointer; size: int; timeout: int): int">recv(socket: Socket; data: pointer; size: int; timeout: int): int</a></li>
- <li><a class="reference" href="#recv%2CSocket%2Cstring%2Cint%2Cint" title="recv(socket: Socket; data: var string; size: int; timeout = -1;
- flags = {SafeDisconn}): int">recv(socket: Socket; data: var string; size: int; timeout = -1;
- flags = {SafeDisconn}): int</a></li>
- <li><a class="reference" href="#recv%2CSocket%2Cint%2Cint" title="recv(socket: Socket; size: int; timeout = -1; flags = {SafeDisconn}): string">recv(socket: Socket; size: int; timeout = -1; flags = {SafeDisconn}): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvFrom
- <li><a class="reference" href="#recvFrom%2CSocket%2Cstring%2Cint%2CT%2CPort%2Cint32" title="recvFrom[T: string | IpAddress](socket: Socket; data: var string; length: int;
- address: var T; port: var Port; flags = 0'i32): int">recvFrom[T: string | IpAddress](socket: Socket; data: var string; length: int;
- address: var T; port: var Port; flags = 0'i32): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">recvLine
- <li><a class="reference" href="#recvLine%2CSocket%2Cint" title="recvLine(socket: Socket; timeout = -1; flags = {SafeDisconn};
- maxLength = MaxLineLength): string">recvLine(socket: Socket; timeout = -1; flags = {SafeDisconn};
- maxLength = MaxLineLength): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">send
- <li><a class="reference" href="#send%2CSocket%2Cpointer%2Cint" title="send(socket: Socket; data: pointer; size: int): int">send(socket: Socket; data: pointer; size: int): int</a></li>
- <li><a class="reference" href="#send%2CSocket%2Cstring%2Cint" title="send(socket: Socket; data: string; flags = {SafeDisconn}; maxRetries = 100)">send(socket: Socket; data: string; flags = {SafeDisconn}; maxRetries = 100)</a></li>
- </ul>
- <ul class="simple nested-toc-section">sendTo
- <li><a class="reference" href="#sendTo%2CSocket%2CIpAddress%2CPort%2Cstring%2Cint32" title="sendTo(socket: Socket; address: IpAddress; port: Port; data: string;
- flags = 0'i32): int">sendTo(socket: Socket; address: IpAddress; port: Port; data: string;
- flags = 0'i32): int</a></li>
- <li><a class="reference" href="#sendTo%2CSocket%2Cstring%2CPort%2Cpointer%2Cint%2CDomain%2Cint32" title="sendTo(socket: Socket; address: string; port: Port; data: pointer; size: int;
- af: Domain = AF_INET; flags = 0'i32)">sendTo(socket: Socket; address: string; port: Port; data: pointer; size: int;
- af: Domain = AF_INET; flags = 0'i32)</a></li>
- <li><a class="reference" href="#sendTo%2CSocket%2Cstring%2CPort%2Cstring" title="sendTo(socket: Socket; address: string; port: Port; data: string)">sendTo(socket: Socket; address: string; port: Port; data: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">serverGetPskFunc
- <li><a class="reference" href="#serverGetPskFunc%2CSslContext" title="serverGetPskFunc(ctx: SslContext): SslServerGetPskFunc">serverGetPskFunc(ctx: SslContext): SslServerGetPskFunc</a></li>
- </ul>
- <ul class="simple nested-toc-section">serverGetPskFunc=
- <li><a class="reference" href="#serverGetPskFunc%3D%2CSslContext%2CSslServerGetPskFunc" title="serverGetPskFunc=(ctx: SslContext; fun: SslServerGetPskFunc)">serverGetPskFunc=(ctx: SslContext; fun: SslServerGetPskFunc)</a></li>
- </ul>
- <ul class="simple nested-toc-section">sessionIdContext=
- <li><a class="reference" href="#sessionIdContext%3D%2CSslContext%2Cstring" title="sessionIdContext=(ctx: SslContext; sidCtx: string)">sessionIdContext=(ctx: SslContext; sidCtx: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">setExtraData
- <li><a class="reference" href="#setExtraData%2CSslContext%2Cint%2CRootRef" title="setExtraData(ctx: SslContext; index: int; data: RootRef)">setExtraData(ctx: SslContext; index: int; data: RootRef)</a></li>
- </ul>
- <ul class="simple nested-toc-section">setSockOpt
- <li><a class="reference" href="#setSockOpt%2CSocket%2CSOBool%2Cbool" title="setSockOpt(socket: Socket; opt: SOBool; value: bool; level = SOL_SOCKET)">setSockOpt(socket: Socket; opt: SOBool; value: bool; level = SOL_SOCKET)</a></li>
- </ul>
- <ul class="simple nested-toc-section">skip
- <li><a class="reference" href="#skip%2CSocket%2Cint%2Cint" title="skip(socket: Socket; size: int; timeout = -1)">skip(socket: Socket; size: int; timeout = -1)</a></li>
- </ul>
- <ul class="simple nested-toc-section">socketError
- <li><a class="reference" href="#socketError%2CSocket%2Cint%2Cset%5BSocketFlag%5D" title="socketError(socket: Socket; err: int = -1; async = false;
- lastError = -1.OSErrorCode; flags: set[SocketFlag] = {})">socketError(socket: Socket; err: int = -1; async = false;
- lastError = -1.OSErrorCode; flags: set[SocketFlag] = {})</a></li>
- </ul>
- <ul class="simple nested-toc-section">sslHandle
- <li><a class="reference" href="#sslHandle%2CSocket" title="sslHandle(self: Socket): SslPtr">sslHandle(self: Socket): SslPtr</a></li>
- </ul>
- <ul class="simple nested-toc-section">toCInt
- <li><a class="reference" href="#toCInt%2CSOBool" title="toCInt(opt: SOBool): cint">toCInt(opt: SOBool): cint</a></li>
- </ul>
- <ul class="simple nested-toc-section">toOSFlags
- <li><a class="reference" href="#toOSFlags%2Cset%5BSocketFlag%5D" title="toOSFlags(socketFlags: set[SocketFlag]): cint">toOSFlags(socketFlags: set[SocketFlag]): cint</a></li>
- </ul>
- <ul class="simple nested-toc-section">toSockAddr
- <li><a class="reference" href="#toSockAddr%2CIpAddress%2CPort%2CSockaddr_storage%2CSockLen" title="toSockAddr(address: IpAddress; port: Port; sa: var Sockaddr_storage;
- sl: var SockLen)">toSockAddr(address: IpAddress; port: Port; sa: var Sockaddr_storage;
- sl: var SockLen)</a></li>
- </ul>
- <ul class="simple nested-toc-section">trySend
- <li><a class="reference" href="#trySend%2CSocket%2Cstring" title="trySend(socket: Socket; data: string): bool">trySend(socket: Socket; data: string): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">wrapConnectedSocket
- <li><a class="reference" href="#wrapConnectedSocket%2CSslContext%2CSocket%2CSslHandshakeType%2Cstring" title="wrapConnectedSocket(ctx: SslContext; socket: Socket;
- handshake: SslHandshakeType; hostname: string = "")">wrapConnectedSocket(ctx: SslContext; socket: Socket;
- handshake: SslHandshakeType; hostname: string = "")</a></li>
- </ul>
- <ul class="simple nested-toc-section">wrapSocket
- <li><a class="reference" href="#wrapSocket%2CSslContext%2CSocket" title="wrapSocket(ctx: SslContext; socket: Socket)">wrapSocket(ctx: SslContext; socket: Socket)</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">&=
- <li><a class="reference" href="#%26%3D.t%2CSocket%2Ctyped" title="`&=`(socket: Socket; data: typed)">`&=`(socket: Socket; data: typed)</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc"><p>This module implements a high-level cross-platform sockets interface. The procedures implemented in this module are primarily for blocking sockets. For asynchronous non-blocking sockets use the <tt class="docutils literal"><span class="pre"><span class="Identifier">asyncnet</span></span></tt> module together with the <tt class="docutils literal"><span class="pre"><span class="Identifier">asyncdispatch</span></span></tt> module.</p>
- <p>The first thing you will always need to do in order to start using sockets, is to create a new instance of the <tt class="docutils literal"><span class="pre"><span class="Identifier">Socket</span></span></tt> type using the <tt class="docutils literal"><span class="pre"><span class="Identifier">newSocket</span></span></tt> procedure.</p>
- <h1><a class="toc-backref" id="ssl" href="#ssl">SSL</a></h1><p>In order to use the SSL procedures defined in this module, you will need to compile your application with the <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">ssl</span></span></tt> flag. See the <a class="reference external" href="net.html#newContext%2Cstring%2Cstring%2Cstring%2Cstring">newContext</a> procedure for additional details.</p>
- <h1><a class="toc-backref" id="ssl-on-windows" href="#ssl-on-windows">SSL on Windows</a></h1><p>On Windows the SSL library checks for valid certificates. It uses the <tt class="docutils literal"><span class="pre"><span class="Identifier">cacert</span><span class="Operator">.</span><span class="Identifier">pem</span></span></tt> file for this purpose which was extracted from <tt class="docutils literal"><span class="pre"><span class="Identifier">https</span><span class="Punctuation">:</span><span class="Operator">//</span><span class="Identifier">curl</span><span class="Operator">.</span><span class="Identifier">se</span><span class="Operator">/</span><span class="Identifier">ca</span><span class="Operator">/</span><span class="Identifier">cacert</span><span class="Operator">.</span><span class="Identifier">pem</span></span></tt>. Besides the OpenSSL DLLs (e.g. libssl-1_1-x64.dll, libcrypto-1_1-x64.dll) you also need to ship <tt class="docutils literal"><span class="pre"><span class="Identifier">cacert</span><span class="Operator">.</span><span class="Identifier">pem</span></span></tt> with your <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">exe</span></span></tt> file.</p>
- <h1><a class="toc-backref" id="examples" href="#examples">Examples</a></h1>
- <h2><a class="toc-backref" id="examples-connecting-to-a-server" href="#examples-connecting-to-a-server">Connecting to a server</a></h2><p>After you create a socket with the <tt class="docutils literal"><span class="pre"><span class="Identifier">newSocket</span></span></tt> procedure, you can easily connect it to a server running at a known hostname (or IP address) and port. To do so over TCP, use the example below.</p>
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">net</span>
- <span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">connect</span><span class="Punctuation">(</span><span class="StringLit">"google.com"</span><span class="Punctuation">,</span> <span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">80</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>For SSL, use the following example:
- <p><strong class="examples_text">Example: cmd: -r:off -d:ssl</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">net</span>
- <span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">let</span> <span class="Identifier">ctx</span> <span class="Operator">=</span> <span class="Identifier">newContext</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">wrapSocket</span><span class="Punctuation">(</span><span class="Identifier">ctx</span><span class="Punctuation">,</span> <span class="Identifier">socket</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">connect</span><span class="Punctuation">(</span><span class="StringLit">"google.com"</span><span class="Punctuation">,</span> <span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">443</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>UDP is a connectionless protocol, so UDP sockets don't have to explicitly call the <a class="reference external" href="net.html#connect%2CSocket%2Cstring">connect</a> procedure. They can simply start sending data immediately.
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">net</span>
- <span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Identifier">AF_INET</span><span class="Punctuation">,</span> <span class="Identifier">SOCK_DGRAM</span><span class="Punctuation">,</span> <span class="Identifier">IPPROTO_UDP</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">sendTo</span><span class="Punctuation">(</span><span class="StringLit">"192.168.0.1"</span><span class="Punctuation">,</span> <span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">27960</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="StringLit">"status</span><span class="EscapeSequence">\n</span><span class="StringLit">"</span><span class="Punctuation">)</span></pre>
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">net</span>
- <span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Identifier">AF_INET</span><span class="Punctuation">,</span> <span class="Identifier">SOCK_DGRAM</span><span class="Punctuation">,</span> <span class="Identifier">IPPROTO_UDP</span><span class="Punctuation">)</span>
- <span class="Keyword">let</span> <span class="Identifier">ip</span> <span class="Operator">=</span> <span class="Identifier">parseIpAddress</span><span class="Punctuation">(</span><span class="StringLit">"192.168.0.1"</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">sendTo</span><span class="Punctuation">(</span><span class="Identifier">ip</span><span class="Punctuation">,</span> <span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">27960</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="StringLit">"status</span><span class="EscapeSequence">\c</span><span class="EscapeSequence">\l</span><span class="StringLit">"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">8</span></pre>
- <h2><a class="toc-backref" id="examples-creating-a-server" href="#examples-creating-a-server">Creating a server</a></h2><p>After you create a socket with the <tt class="docutils literal"><span class="pre"><span class="Identifier">newSocket</span></span></tt> procedure, you can create a TCP server by calling the <tt class="docutils literal"><span class="pre"><span class="Identifier">bindAddr</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">listen</span></span></tt> procedures.</p>
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">net</span>
- <span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">bindAddr</span><span class="Punctuation">(</span><span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">1234</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">listen</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Comment"># You can then begin accepting connections using the `accept` procedure.</span>
- <span class="Keyword">var</span> <span class="Identifier">client</span><span class="Punctuation">:</span> <span class="Identifier">Socket</span>
- <span class="Keyword">var</span> <span class="Identifier">address</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">acceptAddr</span><span class="Punctuation">(</span><span class="Identifier">client</span><span class="Punctuation">,</span> <span class="Identifier">address</span><span class="Punctuation">)</span>
- <span class="Identifier">echo</span> <span class="StringLit">"Client connected from: "</span><span class="Punctuation">,</span> <span class="Identifier">address</span></pre></p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="nativesockets.html">nativesockets</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="times.html">times</a>, <a class="reference external" href="sets.html">sets</a>, <a class="reference external" href="options.html">options</a>, <a class="reference external" href="monotimes.html">monotimes</a>, <a class="reference external" href="ssl_config.html">ssl_config</a>, <a class="reference external" href="winlean.html">winlean</a>, <a class="reference external" href="openssl.html">openssl</a>, <a class="reference external" href="ssl_certs.html">ssl_certs</a>, <a class="reference external" href="posix.html">posix</a>, <a class="reference external" href="posix.html">posix</a>, <a class="reference external" href="posix.html">posix</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="Certificate">
- <dt><pre><a href="net.html#Certificate"><span class="Identifier">Certificate</span></a> <span class="Other">=</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- DER encoded certificate
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L119" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L119" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="IpAddress">
- <dt><pre><a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
- <span class="Keyword">case</span> <span class="Identifier">family</span><span class="Operator">*</span><span class="Other">:</span> <a href="net.html#IpAddressFamily"><span class="Identifier">IpAddressFamily</span></a> <span class="Comment">## the type of the IP address (IPv4 or IPv6)</span>
- <span class="Keyword">of</span> <span class="Identifier">IpAddressFamily</span><span class="Other">.</span><span class="Identifier">IPv6</span><span class="Other">:</span>
- <span class="Identifier">address_v6</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#array"><span class="Identifier">array</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">15</span><span class="Other">,</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a><span class="Other">]</span> <span class="Comment">## Contains the IP address in bytes in</span>
- <span class="Comment">## case of IPv6</span>
- <span class="Keyword">of</span> <span class="Identifier">IpAddressFamily</span><span class="Other">.</span><span class="Identifier">IPv4</span><span class="Other">:</span>
- <span class="Identifier">address_v4</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#array"><span class="Identifier">array</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Other">,</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a><span class="Other">]</span> <span class="Comment">## Contains the IP address in bytes in</span>
- <span class="Comment">## case of IPv4</span></pre></dt>
- <dd>
-
- stores an arbitrary IP address
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L199" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L199" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="IpAddressFamily">
- <dt><pre><a href="net.html#IpAddressFamily"><span class="Identifier">IpAddressFamily</span></a> {.<span class="Identifier">pure</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">IPv6</span><span class="Other">,</span> <span class="Comment">## IPv6 address</span>
- <span class="Identifier">IPv4</span> <span class="Comment">## IPv4 address</span></pre></dt>
- <dd>
-
- Describes the type of an IP address
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L195" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L195" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="ReadLineResult">
- <dt><pre><a href="net.html#ReadLineResult"><span class="Identifier">ReadLineResult</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">ReadFullLine</span><span class="Other">,</span> <span class="Identifier">ReadPartialLine</span><span class="Other">,</span> <span class="Identifier">ReadDisconnected</span><span class="Other">,</span> <span class="Identifier">ReadNone</span></pre></dt>
- <dd>
-
- result for readLineAsync
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L182" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L182" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SOBool">
- <dt><pre><a href="net.html#SOBool"><span class="Identifier">SOBool</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">OptAcceptConn</span><span class="Other">,</span> <span class="Identifier">OptBroadcast</span><span class="Other">,</span> <span class="Identifier">OptDebug</span><span class="Other">,</span> <span class="Identifier">OptDontRoute</span><span class="Other">,</span> <span class="Identifier">OptKeepAlive</span><span class="Other">,</span>
- <span class="Identifier">OptOOBInline</span><span class="Other">,</span> <span class="Identifier">OptReuseAddr</span><span class="Other">,</span> <span class="Identifier">OptReusePort</span><span class="Other">,</span> <span class="Identifier">OptNoDelay</span></pre></dt>
- <dd>
-
- Boolean socket options.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L178" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L178" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="Socket">
- <dt><pre><a href="net.html#Socket"><span class="Identifier">Socket</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="net.html#SocketImpl"><span class="Identifier">SocketImpl</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L176" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L176" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SocketFlag">
- <dt><pre><a href="net.html#SocketFlag"><span class="Identifier">SocketFlag</span></a> {.<span class="Identifier">pure</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">Peek</span><span class="Other">,</span> <span class="Identifier">SafeDisconn</span> <span class="Comment">## Ensures disconnection exceptions (ECONNRESET, EPIPE etc) are not thrown.</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L187" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L187" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SocketImpl">
- <dt><pre><a href="net.html#SocketImpl"><span class="Identifier">SocketImpl</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
- <span class="Keyword">when</span> <span class="Identifier">defineSsl</span><span class="Other">:</span>
- <span class="Comment">## stores the last error on this socket</span></pre></dt>
- <dd>
-
- socket type
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L157" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L157" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslAcceptResult">
- <dt><pre><a href="net.html#SslAcceptResult"><span class="Identifier">SslAcceptResult</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">AcceptNoClient</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">,</span> <span class="Identifier">AcceptNoHandshake</span><span class="Other">,</span> <span class="Identifier">AcceptSuccess</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L134" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L134" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslClientGetPskFunc">
- <dt><pre><a href="net.html#SslClientGetPskFunc"><span class="Identifier">SslClientGetPskFunc</span></a> <span class="Other">=</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">hint</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">identity</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">psk</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L140" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L140" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslContext">
- <dt><pre><a href="net.html#SslContext"><span class="Identifier">SslContext</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
- <span class="Identifier">context</span><span class="Operator">*</span><span class="Other">:</span> <a href="openssl.html#SslCtx"><span class="Identifier">SslCtx</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L129" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L129" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslCVerifyMode">
- <dt><pre><a href="net.html#SslCVerifyMode"><span class="Identifier">SslCVerifyMode</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">CVerifyNone</span><span class="Other">,</span> <span class="Identifier">CVerifyPeer</span><span class="Other">,</span> <span class="Identifier">CVerifyPeerUseEnvVars</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L123" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L123" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslError">
- <dt><pre><a href="net.html#SslError"><span class="Identifier">SslError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#CatchableError"><span class="Identifier">CatchableError</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L121" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L121" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslHandshakeType">
- <dt><pre><a href="net.html#SslHandshakeType"><span class="Identifier">SslHandshakeType</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">handshakeAsClient</span><span class="Other">,</span> <span class="Identifier">handshakeAsServer</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L137" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L137" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslProtVersion">
- <dt><pre><a href="net.html#SslProtVersion"><span class="Identifier">SslProtVersion</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">protSSLv2</span><span class="Other">,</span> <span class="Identifier">protSSLv3</span><span class="Other">,</span> <span class="Identifier">protTLSv1</span><span class="Other">,</span> <span class="Identifier">protSSLv23</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L126" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L126" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="SslServerGetPskFunc">
- <dt><pre><a href="net.html#SslServerGetPskFunc"><span class="Identifier">SslServerGetPskFunc</span></a> <span class="Other">=</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">identity</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L142" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L142" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="TimeoutError">
- <dt><pre><a href="net.html#TimeoutError"><span class="Identifier">TimeoutError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#CatchableError"><span class="Identifier">CatchableError</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L185" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L185" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="10">
- <h1><a class="toc-backref" href="#10">Consts</a></h1>
- <dl class="item">
- <div id="BufferSize">
- <dt><pre><a href="net.html#BufferSize"><span class="Identifier">BufferSize</span></a><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="DecNumber">4000</span></pre></dt>
- <dd>
-
- size of a buffered socket's buffer
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L153" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L153" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="MaxLineLength">
- <dt><pre><a href="net.html#MaxLineLength"><span class="Identifier">MaxLineLength</span></a> <span class="Other">=</span> <span class="DecNumber">1000000</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L154" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L154" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="$-procs-all">
- <div id="$,IpAddress">
- <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CIpAddress"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">address</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Converts an IpAddress into the textual representation
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1922" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1922" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="==-procs-all">
- <div id="==,IpAddress,IpAddress">
- <dt><pre><span class="Keyword">proc</span> <a href="#%3D%3D%2CIpAddress%2CIpAddress"><span class="Identifier">`==`</span></a><span class="Other">(</span><span class="Identifier">lhs</span><span class="Other">,</span> <span class="Identifier">rhs</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Compares two IpAddresses for Equality. Returns true if the addresses are equal
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1911" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1911" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="accept-procs-all">
- <div id="accept,Socket,">
- <dt><pre><span class="Keyword">proc</span> <a href="#accept%2CSocket%2C"><span class="Identifier">accept</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">client</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Socket</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Equivalent to <tt class="docutils literal"><span class="pre"><span class="Identifier">acceptAddr</span></span></tt> but doesn't return the address, only the socket.</p>
- <p>The SocketHandle associated with the resulting client will not be inheritable by child processes by default. This can be changed via the <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> parameter.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">accept</span></span></tt> call may result in an error if the connecting socket disconnects during the duration of the <tt class="docutils literal"><span class="pre"><span class="Identifier">accept</span></span></tt>. If the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is specified then this error will not be raised and instead accept will be called again.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1139" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1139" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="acceptAddr-procs-all">
- <div id="acceptAddr,Socket,,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#acceptAddr%2CSocket%2C%2Cstring"><span class="Identifier">acceptAddr</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">client</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Socket</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span> <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Blocks until a connection is being made from a client. When a connection is made sets <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span></span></tt> to the client socket and <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> to the address of the connecting client. This function will raise OSError if an error occurs.</p>
- <p>The resulting client will inherit any properties of the server socket. For example: whether the socket is buffered or not.</p>
- <p>The SocketHandle associated with the resulting client will not be inheritable by child processes by default. This can be changed via the <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> parameter.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">accept</span></span></tt> call may result in an error if the connecting socket disconnects during the duration of the <tt class="docutils literal"><span class="pre"><span class="Identifier">accept</span></span></tt>. If the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is specified then this error will not be raised and instead accept will be called again.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1040" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1040" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="bindAddr-procs-all">
- <div id="bindAddr,Socket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#bindAddr%2CSocket%2Cstring"><span class="Identifier">bindAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">port</span> <span class="Other">=</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">(</span><span class="DecNumber">0</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">address</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Binds <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>:<tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt> to the socket.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> is "" then ADDR_ANY will be bound.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1018" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1018" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="bindUnix-procs-all">
- <div id="bindUnix,Socket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#bindUnix%2CSocket%2Cstring"><span class="Identifier">bindUnix</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">path</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Binds Unix socket to <tt class="docutils literal"><span class="pre"><span class="Identifier">path</span></span></tt>. This only works on Unix-style systems: Mac OS X, BSD and Linux
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1328" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1328" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="clientGetPskFunc-procs-all">
- <div id="clientGetPskFunc,SslContext">
- <dt><pre><span class="Keyword">proc</span> <a href="#clientGetPskFunc%2CSslContext"><span class="Identifier">clientGetPskFunc</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">)</span><span class="Other">:</span> <a href="net.html#SslClientGetPskFunc"><span class="Identifier">SslClientGetPskFunc</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L756" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L756" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="clientGetPskFunc=-procs-all">
- <div id="clientGetPskFunc=,SslContext,SslClientGetPskFunc">
- <dt><pre><span class="Keyword">proc</span> <a href="#clientGetPskFunc%3D%2CSslContext%2CSslClientGetPskFunc"><span class="Identifier">clientGetPskFunc=</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">fun</span><span class="Other">:</span> <a href="net.html#SslClientGetPskFunc"><span class="Identifier">SslClientGetPskFunc</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Sets function that returns the client identity and the PSK based on identity hint from the server.</p>
- <p>Only used in PSK ciphersuites.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L774" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L774" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="close-procs-all">
- <div id="close,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#close%2CSocket"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">LibraryError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Closes a socket.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is an SSL/TLS socket, this proc will also send a closure notification to the peer. If <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">flags</span></span></tt>, failure to do so due to disconnections will be ignored. This is generally safe in practice. See <a class="reference external" href="https://security.stackexchange.com/a/82044">here</a> for more details.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1215" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1215" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="connect-procs-all">
- <div id="connect,Socket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#connect%2CSocket%2Cstring"><span class="Identifier">connect</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span> <span class="Other">=</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">(</span><span class="DecNumber">0</span><span class="Other">)</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Connects socket to <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>:<tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">Address</span></span></tt> can be an IP address or a host name. If <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> is a host name, this function will try each IP of that host name. <tt class="docutils literal"><span class="pre"><span class="Identifier">htons</span></span></tt> is already performed on <tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt> so you must not do it.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is an SSL socket a handshake will be automatically performed.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L2051" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L2051" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="connect,Socket,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#connect%2CSocket%2Cstring%2Cint"><span class="Identifier">connect</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span> <span class="Other">=</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">(</span><span class="DecNumber">0</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">timeout</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">,</span> <a href="system.html#RootEffect"><span class="Identifier">RootEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">TimeoutError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Connects to server as specified by <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> on port specified by <tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt>.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">timeout</span></span></tt> parameter specifies the time in milliseconds to allow for the connection to the server to be made.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L2126" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L2126" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="connectUnix-procs-all">
- <div id="connectUnix,Socket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#connectUnix%2CSocket%2Cstring"><span class="Identifier">connectUnix</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">path</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Connects to Unix socket on <tt class="docutils literal"><span class="pre"><span class="Identifier">path</span></span></tt>. This only works on Unix-style systems: Mac OS X, BSD and Linux
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1319" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1319" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="destroyContext-procs-all">
- <div id="destroyContext,SslContext">
- <dt><pre><span class="Keyword">proc</span> <a href="#destroyContext%2CSslContext"><span class="Identifier">destroyContext</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Free memory referenced by SslContext.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L739" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L739" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="dial-procs-all">
- <div id="dial,string,Port">
- <dt><pre><span class="Keyword">proc</span> <a href="#dial%2Cstring%2CPort"><span class="Identifier">dial</span></a><span class="Other">(</span><span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">protocol</span> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <span class="Identifier">Socket</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Establishes connection to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>:<tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt> pair via the specified protocol. The procedure iterates through possible resolutions of the <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> until it succeeds, meaning that it seamlessly works with both IPv4 and IPv6. Returns Socket ready to send or receive data.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1990" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1990" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="fromSockAddr-procs-all">
- <div id="fromSockAddr,,SockLen,IpAddress,Port">
- <dt><pre><span class="Keyword">proc</span> <a href="#fromSockAddr%2C%2CSockLen%2CIpAddress%2CPort"><span class="Identifier">fromSockAddr</span></a><span class="Other">(</span><span class="Identifier">sa</span><span class="Other">:</span> <a href="winlean.html#Sockaddr_storage"><span class="Identifier">Sockaddr_storage</span></a> <span class="Operator">|</span> <a href="winlean.html#SockAddr"><span class="Identifier">SockAddr</span></a> <span class="Operator">|</span> <a href="winlean.html#Sockaddr_in"><span class="Identifier">Sockaddr_in</span></a> <span class="Operator">|</span> <a href="winlean.html#Sockaddr_in6"><span class="Identifier">Sockaddr_in6</span></a><span class="Other">;</span>
- <span class="Identifier">sl</span><span class="Other">:</span> <a href="winlean.html#SockLen"><span class="Identifier">SockLen</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- Converts <tt class="docutils literal"><span class="pre"><span class="Identifier">SockAddr</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">SockLen</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">IpAddress</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">Port</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">ObjectConversionDefect</span></span></tt> in case of invalid <tt class="docutils literal"><span class="pre"><span class="Identifier">sa</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">sl</span></span></tt> arguments.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L544" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L544" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getExtraData-procs-all">
- <div id="getExtraData,SslContext,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#getExtraData%2CSslContext%2Cint"><span class="Identifier">getExtraData</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#RootRef"><span class="Identifier">RootRef</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieves arbitrary data stored inside SslContext.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L580" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L580" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getFd-procs-all">
- <div id="getFd,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getFd%2CSocket"><span class="Identifier">getFd</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="winlean.html#SocketHandle"><span class="Identifier">SocketHandle</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the socket's file descriptor
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1860" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1860" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getLocalAddr-procs-all">
- <div id="getLocalAddr,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getLocalAddr%2CSocket"><span class="Identifier">getLocalAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Get the socket's local address and port number.</p>
- <p>This is high-level interface for <span id="getsockname_1">getsockname</span>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1295" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1295" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPeerAddr-procs-all">
- <div id="getPeerAddr,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPeerAddr%2CSocket"><span class="Identifier">getPeerAddr</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Get the socket's peer address and port number.</p>
- <p>This is high-level interface for <span id="getpeername_1">getpeername</span>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1302" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1302" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPeerCertificates-procs-all">
- <div id="getPeerCertificates,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPeerCertificates%2CSocket"><span class="Identifier">getPeerCertificates</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="net.html#Certificate"><span class="Identifier">Certificate</span></a><span class="Other">]</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the certificate chain received by the peer we are connected to through the given socket. The handshake must have been completed and the certificate chain must have been verified successfully or else an empty sequence is returned. The chain is ordered from leaf certificate to root certificate.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L908" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L908" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="getPeerCertificates,SslPtr">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPeerCertificates%2CSslPtr"><span class="Identifier">getPeerCertificates</span></a><span class="Other">(</span><span class="Identifier">sslHandle</span><span class="Other">:</span> <a href="openssl.html#SslPtr"><span class="Identifier">SslPtr</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="net.html#Certificate"><span class="Identifier">Certificate</span></a><span class="Other">]</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the certificate chain received by the peer we are connected to through the OpenSSL connection represented by <tt class="docutils literal"><span class="pre"><span class="Identifier">sslHandle</span></span></tt>. The handshake must have been completed and the certificate chain must have been verified successfully or else an empty sequence is returned. The chain is ordered from leaf certificate to root certificate.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L889" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L889" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPrimaryIPAddr-procs-all">
- <div id="getPrimaryIPAddr">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPrimaryIPAddr"><span class="Identifier">getPrimaryIPAddr</span></a><span class="Other">(</span><span class="Identifier">dest</span> <span class="Other">=</span> <span class="Identifier">parseIpAddress</span><span class="Other">(</span><span class="StringLit">"8.8.8.8"</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">LibraryError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Finds the local IP address, usually assigned to eth0 on LAN or wlan0 on WiFi, used to reach an external address. Useful to run local services.</p>
- <p>No traffic is sent.</p>
- <p>Supports IPv4 and v6. Raises OSError if external networking is not set up.</p>
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Identifier">echo</span> <span class="Identifier">getPrimaryIPAddr</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Comment"># "192.168.1.2"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L2158" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L2158" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPskIdentity-procs-all">
- <div id="getPskIdentity,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getPskIdentity%2CSocket"><span class="Identifier">getPskIdentity</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Gets the PSK identity provided by the client.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L804" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L804" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getSocketError-procs-all">
- <div id="getSocketError,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#getSocketError%2CSocket"><span class="Identifier">getSocketError</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="oserrors.html#OSErrorCode"><span class="Identifier">OSErrorCode</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Checks <tt class="docutils literal"><span class="pre"><span class="Identifier">osLastError</span></span></tt> for a valid error. If it has been reset it uses the last error stored in the socket object.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L935" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L935" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getSockOpt-procs-all">
- <div id="getSockOpt,Socket,SOBool">
- <dt><pre><span class="Keyword">proc</span> <a href="#getSockOpt%2CSocket%2CSOBool"><span class="Identifier">getSockOpt</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">opt</span><span class="Other">:</span> <a href="net.html#SOBool"><span class="Identifier">SOBool</span></a><span class="Other">;</span> <span class="Identifier">level</span> <span class="Other">=</span> <span class="Identifier">SOL_SOCKET</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieves option <tt class="docutils literal"><span class="pre"><span class="Identifier">opt</span></span></tt> as a boolean value.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1289" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1289" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="gotHandshake-procs-all">
- <div id="gotHandshake,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#gotHandshake%2CSocket"><span class="Identifier">gotHandshake</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Determines whether a handshake has occurred between a client (<tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>) and the server that <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is connected to.</p>
- <p>Throws SslError if <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is not an SSL socket.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1338" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1338" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hasDataBuffered-procs-all">
- <div id="hasDataBuffered,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#hasDataBuffered%2CSocket"><span class="Identifier">hasDataBuffered</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether a socket has data buffered.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1348" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1348" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="IPv4_any-procs-all">
- <div id="IPv4_any">
- <dt><pre><span class="Keyword">proc</span> <a href="#IPv4_any"><span class="Identifier">IPv4_any</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the IPv4 any address, which can be used to listen on all available network adapters
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1876" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1876" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="IPv4_broadcast-procs-all">
- <div id="IPv4_broadcast">
- <dt><pre><span class="Keyword">proc</span> <a href="#IPv4_broadcast"><span class="Identifier">IPv4_broadcast</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the IPv4 broadcast address (255.255.255.255)
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1889" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1889" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="IPv4_loopback-procs-all">
- <div id="IPv4_loopback">
- <dt><pre><span class="Keyword">proc</span> <a href="#IPv4_loopback"><span class="Identifier">IPv4_loopback</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the IPv4 loopback address (127.0.0.1)
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1883" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1883" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="IPv6_any-procs-all">
- <div id="IPv6_any">
- <dt><pre><span class="Keyword">proc</span> <a href="#IPv6_any"><span class="Identifier">IPv6_any</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the IPv6 any address (::0), which can be used to listen on all available network adapters
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1895" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1895" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="IPv6_loopback-procs-all">
- <div id="IPv6_loopback">
- <dt><pre><span class="Keyword">proc</span> <a href="#IPv6_loopback"><span class="Identifier">IPv6_loopback</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the IPv6 loopback address (::1)
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1902" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1902" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isDisconnectionError-procs-all">
- <div id="isDisconnectionError,set[SocketFlag],OSErrorCode">
- <dt><pre><span class="Keyword">proc</span> <a href="#isDisconnectionError%2Cset%5BSocketFlag%5D%2COSErrorCode"><span class="Identifier">isDisconnectionError</span></a><span class="Other">(</span><span class="Identifier">flags</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="net.html#SocketFlag"><span class="Identifier">SocketFlag</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">lastError</span><span class="Other">:</span> <a href="oserrors.html#OSErrorCode"><span class="Identifier">OSErrorCode</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether <tt class="docutils literal"><span class="pre"><span class="Identifier">lastError</span></span></tt> is a disconnection error. Only does this if flags contains <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L238" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L238" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isIpAddress-procs-all">
- <div id="isIpAddress,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#isIpAddress%2Cstring"><span class="Identifier">isIpAddress</span></a><span class="Other">(</span><span class="Identifier">addressStr</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Checks if a string is an IP address Returns true if it is, false otherwise
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L497" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L497" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isSsl-procs-all">
- <div id="isSsl,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#isSsl%2CSocket"><span class="Identifier">isSsl</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Determines whether <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is a SSL socket.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1853" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1853" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="listen-procs-all">
- <div id="listen,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#listen%2CSocket"><span class="Identifier">listen</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">backlog</span> <span class="Other">=</span> <span class="Identifier">SOMAXCONN</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Marks <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> as accepting connections. <tt class="docutils literal"><span class="pre"><span class="Identifier">Backlog</span></span></tt> specifies the maximum length of the queue of pending connections.</p>
- <p>Raises an OSError error upon failure.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1009" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1009" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newContext-procs-all">
- <div id="newContext,string,string,string,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#newContext%2Cstring%2Cstring%2Cstring%2Cstring"><span class="Identifier">newContext</span></a><span class="Other">(</span><span class="Identifier">protVersion</span> <span class="Other">=</span> <span class="Identifier">protSSLv23</span><span class="Other">;</span> <span class="Identifier">verifyMode</span> <span class="Other">=</span> <span class="Identifier">CVerifyPeer</span><span class="Other">;</span>
- <span class="Identifier">certFile</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span> <span class="Identifier">keyFile</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span> <span class="Identifier">cipherList</span> <span class="Other">=</span> <span class="Identifier">CiphersIntermediate</span><span class="Other">;</span>
- <span class="Identifier">caDir</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span> <span class="Identifier">caFile</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">;</span> <span class="Identifier">ciphersuites</span> <span class="Other">=</span> <span class="Identifier">CiphersModern</span><span class="Other">)</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">LibraryError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">ReadEnvEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates an SSL context.</p>
- <p>Protocol version is currently ignored by default and TLS is used. With <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">openssl10</span></span></tt>, only SSLv23 and TLSv1 may be used.</p>
- <p>There are three options for verify mode: <tt class="docutils literal"><span class="pre"><span class="Identifier">CVerifyNone</span></span></tt>: certificates are not verified; <tt class="docutils literal"><span class="pre"><span class="Identifier">CVerifyPeer</span></span></tt>: certificates are verified; <tt class="docutils literal"><span class="pre"><span class="Identifier">CVerifyPeerUseEnvVars</span></span></tt>: certificates are verified and the optional environment variables SSL_CERT_FILE and SSL_CERT_DIR are also used to locate certificates</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">nimDisableCertificateValidation</span></span></tt> define overrides verifyMode and disables certificate verification globally!</p>
- <p>CA certificates will be loaded, in the following order, from:</p>
- <ul class="simple"><li>caFile, caDir, parameters, if set</li>
- <li>if <tt class="docutils literal"><span class="pre"><span class="Identifier">verifyMode</span></span></tt> is set to <tt class="docutils literal"><span class="pre"><span class="Identifier">CVerifyPeerUseEnvVars</span></span></tt>, the SSL_CERT_FILE and SSL_CERT_DIR environment variables are used</li>
- <li>a set of files and directories from the <a class="reference external" href="ssl_certs.html">ssl_certs</a> file.</li>
- </ul>
- <p>The last two parameters specify the certificate file path and the key file path, a server socket will most likely not work without these.</p>
- <p>Certificates can be generated using the following command:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Identifier">openssl</span> <span class="Identifier">req</span> <span class="Operator">-</span><span class="Identifier">x509</span> <span class="Operator">-</span><span class="Identifier">nodes</span> <span class="Operator">-</span><span class="Identifier">days</span> <span class="DecNumber">365</span> <span class="Operator">-</span><span class="Identifier">newkey</span> <span class="Identifier">rsa</span><span class="Punctuation">:</span><span class="DecNumber">4096</span> <span class="Operator">-</span><span class="Identifier">keyout</span> <span class="Identifier">mykey</span><span class="Operator">.</span><span class="Identifier">pem</span> <span class="Operator">-</span><span class="Keyword">out</span> <span class="Identifier">mycert</span><span class="Operator">.</span><span class="Identifier">pem</span></span></tt></li>
- </ul>
- <p>or using ECDSA:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Identifier">openssl</span> <span class="Identifier">ecparam</span> <span class="Operator">-</span><span class="Keyword">out</span> <span class="Identifier">mykey</span><span class="Operator">.</span><span class="Identifier">pem</span> <span class="Operator">-</span><span class="Identifier">name</span> <span class="Identifier">secp256k1</span> <span class="Operator">-</span><span class="Identifier">genkey</span></span></tt></li>
- <li><tt class="docutils literal"><span class="pre"><span class="Identifier">openssl</span> <span class="Identifier">req</span> <span class="Operator">-</span><span class="Identifier">new</span> <span class="Operator">-</span><span class="Identifier">key</span> <span class="Identifier">mykey</span><span class="Operator">.</span><span class="Identifier">pem</span> <span class="Operator">-</span><span class="Identifier">x509</span> <span class="Operator">-</span><span class="Identifier">nodes</span> <span class="Operator">-</span><span class="Identifier">days</span> <span class="DecNumber">365</span> <span class="Operator">-</span><span class="Keyword">out</span> <span class="Identifier">mycert</span><span class="Operator">.</span><span class="Identifier">pem</span></span></tt></li>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L624" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L624" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newSocket-procs-all">
- <div id="newSocket,cint,cint,cint">
- <dt><pre><span class="Keyword">proc</span> <a href="#newSocket%2Ccint%2Ccint%2Ccint"><span class="Identifier">newSocket</span></a><span class="Other">(</span><span class="Identifier">domain</span><span class="Other">,</span> <span class="Identifier">sockType</span><span class="Other">,</span> <span class="Identifier">protocol</span><span class="Other">:</span> <a href="ctypes.html#cint"><span class="Identifier">cint</span></a><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Socket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new socket.</p>
- <p>The SocketHandle associated with the resulting Socket will not be inheritable by child processes by default. This can be changed via the <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> parameter.</p>
- <p>If an error occurs OSError will be raised.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L283" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L283" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newSocket,Domain,SockType,Protocol">
- <dt><pre><span class="Keyword">proc</span> <a href="#newSocket%2CDomain%2CSockType%2CProtocol"><span class="Identifier">newSocket</span></a><span class="Other">(</span><span class="Identifier">domain</span><span class="Other">:</span> <a href="nativesockets.html#Domain"><span class="Identifier">Domain</span></a> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">;</span> <span class="Identifier">sockType</span><span class="Other">:</span> <a href="nativesockets.html#SockType"><span class="Identifier">SockType</span></a> <span class="Other">=</span> <span class="Identifier">SOCK_STREAM</span><span class="Other">;</span>
- <span class="Identifier">protocol</span><span class="Other">:</span> <a href="nativesockets.html#Protocol"><span class="Identifier">Protocol</span></a> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
- <span class="Identifier">inheritable</span> <span class="Other">=</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">nimInheritHandles</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Socket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new socket.</p>
- <p>The SocketHandle associated with the resulting Socket will not be inheritable by child processes by default. This can be changed via the <tt class="docutils literal"><span class="pre"><span class="Identifier">inheritable</span></span></tt> parameter.</p>
- <p>If an error occurs OSError will be raised.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L298" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L298" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newSocket,SocketHandle,Domain,SockType,Protocol">
- <dt><pre><span class="Keyword">proc</span> <a href="#newSocket%2CSocketHandle%2CDomain%2CSockType%2CProtocol"><span class="Identifier">newSocket</span></a><span class="Other">(</span><span class="Identifier">fd</span><span class="Other">:</span> <a href="winlean.html#SocketHandle"><span class="Identifier">SocketHandle</span></a><span class="Other">;</span> <span class="Identifier">domain</span><span class="Other">:</span> <a href="nativesockets.html#Domain"><span class="Identifier">Domain</span></a> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">;</span>
- <span class="Identifier">sockType</span><span class="Other">:</span> <a href="nativesockets.html#SockType"><span class="Identifier">SockType</span></a> <span class="Other">=</span> <span class="Identifier">SOCK_STREAM</span><span class="Other">;</span>
- <span class="Identifier">protocol</span><span class="Other">:</span> <a href="nativesockets.html#Protocol"><span class="Identifier">Protocol</span></a> <span class="Other">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Other">;</span> <span class="Identifier">buffered</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Socket</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Creates a new socket as specified by the params.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L265" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L265" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseIpAddress-procs-all">
- <div id="parseIpAddress,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseIpAddress%2Cstring"><span class="Identifier">parseIpAddress</span></a><span class="Other">(</span><span class="Identifier">addressStr</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Parses an IP address</p>
- <p>Raises ValueError on error.</p>
- <p>For IPv4 addresses, only the strict form as defined in RFC 6943 is considered valid, see <a class="reference external" href="https://datatracker.ietf.org/doc/html/rfc6943#section-3.1.1">https://datatracker.ietf.org/doc/html/rfc6943#section-3.1.1</a>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L482" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L482" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="pskIdentityHint=-procs-all">
- <div id="pskIdentityHint=,SslContext,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#pskIdentityHint%3D%2CSslContext%2Cstring"><span class="Identifier">pskIdentityHint=</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">hint</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Sets the identity hint passed to server.</p>
- <p>Only used in PSK ciphersuites.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L749" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L749" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="raiseSSLError-procs-all">
- <div id="raiseSSLError,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#raiseSSLError%2Cstring"><span class="Identifier">raiseSSLError</span></a><span class="Other">(</span><span class="Identifier">s</span> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="net.html#SslError"><span class="Identifier">SslError</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Raises a new SSL error.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L564" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L564" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readLine-procs-all">
- <div id="readLine,Socket,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CSocket%2Cstring%2Cint"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">line</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span> <span class="Identifier">maxLength</span> <span class="Other">=</span> <span class="Identifier">MaxLineLength</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads a line of data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>.</p>
- <p>If a full line is read <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is not added to <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>, however if solely <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read then <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to it.</p>
- <p>If the socket is disconnected, <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>.</p>
- <p>An OSError exception will be raised in the case of a socket error.</p>
- <p>A timeout can be specified in milliseconds, if data is not received within the specified time a TimeoutError exception will be raised.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">maxLength</span></span></tt> parameter determines the maximum amount of characters that can be read. The result is truncated after that.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- Only the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is currently supported.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1577" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1577" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recv-procs-all">
- <div id="recv,Socket,pointer,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recv%2CSocket%2Cpointer%2Cint"><span class="Identifier">recv</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Receives data from a socket.</p>
- <p><strong>Note</strong>: This is a low-level function, you may be interested in the higher level versions of this function which are also named <tt class="docutils literal"><span class="pre"><span class="Identifier">recv</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1397" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1397" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="recv,Socket,pointer,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recv%2CSocket%2Cpointer%2Cint%2Cint"><span class="Identifier">recv</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">timeout</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#TimeEffect"><span class="Identifier">TimeEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- overload with a <tt class="docutils literal"><span class="pre"><span class="Identifier">timeout</span></span></tt> parameter in milliseconds.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1479" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1479" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="recv,Socket,string,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recv%2CSocket%2Cstring%2Cint%2Cint"><span class="Identifier">recv</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Higher-level version of <tt class="docutils literal"><span class="pre"><span class="Identifier">recv</span></span></tt>.</p>
- <p>Reads <strong>up to</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt>.</p>
- <p>For buffered sockets this function will attempt to read all the requested data. It will read this data in <tt class="docutils literal"><span class="pre"><span class="Identifier">BufferSize</span></span></tt> chunks.</p>
- <p>For unbuffered sockets this function makes no effort to read all the data requested. It will return as much data as the operating system gives it.</p>
- <p>When 0 is returned the socket's connection has been closed.</p>
- <p>This function will throw an OSError exception when an error occurs. A value lower than 0 is never returned.</p>
- <p>A timeout may be specified in milliseconds, if enough data is not received within the time specified a TimeoutError exception will be raised.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- Only the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is currently supported.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1497" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1497" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="recv,Socket,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recv%2CSocket%2Cint%2Cint"><span class="Identifier">recv</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
- <span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Higher-level version of <tt class="docutils literal"><span class="pre"><span class="Identifier">recv</span></span></tt> which returns a string.</p>
- <p>Reads <strong>up to</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into the result.</p>
- <p>For buffered sockets this function will attempt to read all the requested data. It will read this data in <tt class="docutils literal"><span class="pre"><span class="Identifier">BufferSize</span></span></tt> chunks.</p>
- <p>For unbuffered sockets this function makes no effort to read all the data requested. It will return as much data as the operating system gives it.</p>
- <p>When <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt> is returned the socket's connection has been closed.</p>
- <p>This function will throw an OSError exception when an error occurs.</p>
- <p>A timeout may be specified in milliseconds, if enough data is not received within the time specified a TimeoutError exception will be raised.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- Only the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is currently supported.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1532" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1532" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvFrom-procs-all">
- <div id="recvFrom,Socket,string,int,T,Port,int32">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvFrom%2CSocket%2Cstring%2Cint%2CT%2CPort%2Cint32"><span class="Identifier">recvFrom</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Operator">|</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
- <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span>
- <span class="Identifier">port</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="DecNumber">0'i32</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Receives data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. This function should normally be used with connection-less sockets (UDP sockets). The source address of the data packet is stored in the <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt> argument as either a string or an IpAddress.</p>
- <p>If an error occurs an OSError exception will be raised. Otherwise the return value will be the length of data received.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- This function does not yet have a buffered implementation, so when <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> is buffered the non-buffered implementation will be used. Therefore if <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> contains something in its buffer this function will make no effort to return it.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1657" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1657" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="recvLine-procs-all">
- <div id="recvLine,Socket,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#recvLine%2CSocket%2Cint"><span class="Identifier">recvLine</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span>
- <span class="Identifier">maxLength</span> <span class="Other">=</span> <span class="Identifier">MaxLineLength</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Reads a line of data from <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>.</p>
- <p>If a full line is read <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is not added to the result, however if solely <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">L</span></span></tt> is read then the result will be set to it.</p>
- <p>If the socket is disconnected, the result will be set to <tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>.</p>
- <p>An OSError exception will be raised in the case of a socket error.</p>
- <p>A timeout can be specified in milliseconds, if data is not received within the specified time a TimeoutError exception will be raised.</p>
- <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">maxLength</span></span></tt> parameter determines the maximum amount of characters that can be read. The result is truncated after that.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- Only the <tt class="docutils literal"><span class="pre"><span class="Identifier">SafeDisconn</span></span></tt> flag is currently supported.</div>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1634" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1634" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="send-procs-all">
- <div id="send,Socket,pointer,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#send%2CSocket%2Cpointer%2Cint"><span class="Identifier">send</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Sends data to a socket.</p>
- <p><strong>Note</strong>: This is a low-level version of <tt class="docutils literal"><span class="pre"><span class="Identifier">send</span></span></tt>. You likely should use the version below.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1720" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1720" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="send,Socket,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#send%2CSocket%2Cstring%2Cint"><span class="Identifier">send</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">SafeDisconn</span><span class="Other">}</span><span class="Other">;</span> <span class="Identifier">maxRetries</span> <span class="Other">=</span> <span class="DecNumber">100</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sends data to a socket. Will try to send all the data by handling interrupts and incomplete writes up to <tt class="docutils literal"><span class="pre"><span class="Identifier">maxRetries</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1739" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1739" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sendTo-procs-all">
- <div id="sendTo,Socket,IpAddress,Port,string,int32">
- <dt><pre><span class="Keyword">proc</span> <a href="#sendTo%2CSocket%2CIpAddress%2CPort%2Cstring%2Cint32"><span class="Identifier">sendTo</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
- <span class="Identifier">flags</span> <span class="Other">=</span> <span class="DecNumber">0'i32</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>This proc sends <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">IpAddress</span></span></tt> and returns the number of bytes written.</p>
- <p>Generally for use with connection-less (UDP) sockets.</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p>This is the high-level version of the above <tt class="docutils literal"><span class="pre"><span class="Identifier">sendTo</span></span></tt> function.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1828" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1828" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="sendTo,Socket,string,Port,pointer,int,Domain,int32">
- <dt><pre><span class="Keyword">proc</span> <a href="#sendTo%2CSocket%2Cstring%2CPort%2Cpointer%2Cint%2CDomain%2Cint32"><span class="Identifier">sendTo</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span>
- <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">af</span><span class="Other">:</span> <a href="nativesockets.html#Domain"><span class="Identifier">Domain</span></a> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="DecNumber">0'i32</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>This proc sends <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>, which may be an IP address or a hostname, if a hostname is specified this function will try each IP of that hostname. This function should normally be used with connection-less sockets (UDP sockets).</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p><strong>Note:</strong> You may wish to use the high-level version of this function which is defined below.</p>
- <p><strong>Note:</strong> This proc is not available for SSL sockets.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1780" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1780" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="sendTo,Socket,string,Port,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#sendTo%2CSocket%2Cstring%2CPort%2Cstring"><span class="Identifier">sendTo</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">address</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>This proc sends <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">address</span></span></tt>, which may be an IP address or a hostname, if a hostname is specified this function will try each IP of that hostname.</p>
- <p>Generally for use with connection-less (UDP) sockets.</p>
- <p>If an error occurs an OSError exception will be raised.</p>
- <p>This is the high-level version of the above <tt class="docutils literal"><span class="pre"><span class="Identifier">sendTo</span></span></tt> function.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1815" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1815" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="serverGetPskFunc-procs-all">
- <div id="serverGetPskFunc,SslContext">
- <dt><pre><span class="Keyword">proc</span> <a href="#serverGetPskFunc%2CSslContext"><span class="Identifier">serverGetPskFunc</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">)</span><span class="Other">:</span> <a href="net.html#SslServerGetPskFunc"><span class="Identifier">SslServerGetPskFunc</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L783" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L783" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="serverGetPskFunc=-procs-all">
- <div id="serverGetPskFunc=,SslContext,SslServerGetPskFunc">
- <dt><pre><span class="Keyword">proc</span> <a href="#serverGetPskFunc%3D%2CSslContext%2CSslServerGetPskFunc"><span class="Identifier">serverGetPskFunc=</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">fun</span><span class="Other">:</span> <a href="net.html#SslServerGetPskFunc"><span class="Identifier">SslServerGetPskFunc</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Sets function that returns PSK based on the client identity.</p>
- <p>Only used in PSK ciphersuites.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L796" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L796" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sessionIdContext=-procs-all">
- <div id="sessionIdContext=,SslContext,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#sessionIdContext%3D%2CSslContext%2Cstring"><span class="Identifier">sessionIdContext=</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">sidCtx</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Sets the session id context in which a session can be reused. Used for permitting clients to reuse a session id instead of doing a new handshake.</p>
- <p>TLS clients might attempt to resume a session using the session id context, thus it must be set if verifyMode is set to CVerifyPeer or CVerifyPeerUseEnvVars, otherwise the connection will fail and SslError will be raised if resumption occurs.</p>
- <ul class="simple"><li>Only useful if set server-side.</li>
- <li>Should be unique per-application to prevent clients from malfunctioning.</li>
- <li>sidCtx must be at most 32 characters in length.</li>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L919" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L919" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setExtraData-procs-all">
- <div id="setExtraData,SslContext,int,RootRef">
- <dt><pre><span class="Keyword">proc</span> <a href="#setExtraData%2CSslContext%2Cint%2CRootRef"><span class="Identifier">setExtraData</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#RootRef"><span class="Identifier">RootRef</span></a><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Stores arbitrary data inside SslContext. The unique <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt> should be retrieved using getSslContextExtraDataIndex.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L589" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L589" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setSockOpt-procs-all">
- <div id="setSockOpt,Socket,SOBool,bool">
- <dt><pre><span class="Keyword">proc</span> <a href="#setSockOpt%2CSocket%2CSOBool%2Cbool"><span class="Identifier">setSockOpt</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">opt</span><span class="Other">:</span> <a href="net.html#SOBool"><span class="Identifier">SOBool</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a><span class="Other">;</span> <span class="Identifier">level</span> <span class="Other">=</span> <span class="Identifier">SOL_SOCKET</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sets option <tt class="docutils literal"><span class="pre"><span class="Identifier">opt</span></span></tt> to a boolean value specified by <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt>.
- <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">socket</span> <span class="Operator">=</span> <span class="Identifier">newSocket</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">setSockOpt</span><span class="Punctuation">(</span><span class="Identifier">OptReusePort</span><span class="Punctuation">,</span> <span class="Identifier">true</span><span class="Punctuation">)</span>
- <span class="Identifier">socket</span><span class="Operator">.</span><span class="Identifier">setSockOpt</span><span class="Punctuation">(</span><span class="Identifier">OptNoDelay</span><span class="Punctuation">,</span> <span class="Identifier">true</span><span class="Punctuation">,</span> <span class="Identifier">level</span> <span class="Operator">=</span> <span class="Identifier">IPPROTO_TCP</span><span class="Operator">.</span><span class="Identifier">cint</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1308" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1308" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skip-procs-all">
- <div id="skip,Socket,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skip%2CSocket%2Cint%2Cint"><span class="Identifier">skip</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeoutError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Skips <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> amount of bytes.</p>
- <p>An optional timeout can be specified in milliseconds, if skipping the bytes takes longer than specified a TimeoutError exception will be raised.</p>
- <p>Returns the number of skipped bytes.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1705" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1705" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="socketError-procs-all">
- <div id="socketError,Socket,int,set[SocketFlag]">
- <dt><pre><span class="Keyword">proc</span> <a href="#socketError%2CSocket%2Cint%2Cset%5BSocketFlag%5D"><span class="Identifier">socketError</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">err</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">async</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span>
- <span class="Identifier">lastError</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">.</span><span class="Identifier">OSErrorCode</span><span class="Other">;</span> <span class="Identifier">flags</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="net.html#SocketFlag"><span class="Identifier">SocketFlag</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Other">}</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L234" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L234" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sslHandle-procs-all">
- <div id="sslHandle,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#sslHandle%2CSocket"><span class="Identifier">sslHandle</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span><span class="Other">:</span> <a href="openssl.html#SslPtr"><span class="Identifier">SslPtr</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieve the ssl pointer of <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt>. Useful for interfacing with <tt class="docutils literal"><span class="pre"><span class="Identifier">openssl</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L559" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L559" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toCInt-procs-all">
- <div id="toCInt,SOBool">
- <dt><pre><span class="Keyword">proc</span> <a href="#toCInt%2CSOBool"><span class="Identifier">toCInt</span></a><span class="Other">(</span><span class="Identifier">opt</span><span class="Other">:</span> <a href="net.html#SOBool"><span class="Identifier">SOBool</span></a><span class="Other">)</span><span class="Other">:</span> <a href="ctypes.html#cint"><span class="Identifier">cint</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Converts a <tt class="docutils literal"><span class="pre"><span class="Identifier">SOBool</span></span></tt> into its Socket Option cint representation.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1276" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1276" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toOSFlags-procs-all">
- <div id="toOSFlags,set[SocketFlag]">
- <dt><pre><span class="Keyword">proc</span> <a href="#toOSFlags%2Cset%5BSocketFlag%5D"><span class="Identifier">toOSFlags</span></a><span class="Other">(</span><span class="Identifier">socketFlags</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="net.html#SocketFlag"><span class="Identifier">SocketFlag</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="ctypes.html#cint"><span class="Identifier">cint</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Converts the flags into the underlying OS representation.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L256" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L256" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toSockAddr-procs-all">
- <div id="toSockAddr,IpAddress,Port,Sockaddr_storage,SockLen">
- <dt><pre><span class="Keyword">proc</span> <a href="#toSockAddr%2CIpAddress%2CPort%2CSockaddr_storage%2CSockLen"><span class="Identifier">toSockAddr</span></a><span class="Other">(</span><span class="Identifier">address</span><span class="Other">:</span> <a href="net.html#IpAddress"><span class="Identifier">IpAddress</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">sa</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="winlean.html#Sockaddr_storage"><span class="Identifier">Sockaddr_storage</span></a><span class="Other">;</span>
- <span class="Identifier">sl</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="winlean.html#SockLen"><span class="Identifier">SockLen</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Converts <tt class="docutils literal"><span class="pre"><span class="Identifier">IpAddress</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">Port</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">SockAddr</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">SockLen</span></span></tt>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L506" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L506" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="trySend-procs-all">
- <div id="trySend,Socket,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#trySend%2CSocket%2Cstring"><span class="Identifier">trySend</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Safe alternative to <tt class="docutils literal"><span class="pre"><span class="Identifier">send</span></span></tt>. Does not raise an OSError when an error occurs, and instead returns <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> on failure.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1775" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1775" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="wrapConnectedSocket-procs-all">
- <div id="wrapConnectedSocket,SslContext,Socket,SslHandshakeType,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#wrapConnectedSocket%2CSslContext%2CSocket%2CSslHandshakeType%2Cstring"><span class="Identifier">wrapConnectedSocket</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span>
- <span class="Identifier">handshake</span><span class="Other">:</span> <a href="net.html#SslHandshakeType"><span class="Identifier">SslHandshakeType</span></a><span class="Other">;</span> <span class="Identifier">hostname</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Wraps a connected socket in an SSL context. This function effectively turns <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into an SSL socket. <tt class="docutils literal"><span class="pre"><span class="Identifier">hostname</span></span></tt> should be specified so that the client knows which hostname the server certificate should be validated against.</p>
- <p>This should be called on a connected socket, and will perform an SSL handshake immediately.</p>
- <p>FIXME: <strong>Disclaimer</strong>: This code is not well tested, may be very unsafe and prone to security vulnerabilities.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L856" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L856" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="wrapSocket-procs-all">
- <div id="wrapSocket,SslContext,Socket">
- <dt><pre><span class="Keyword">proc</span> <a href="#wrapSocket%2CSslContext%2CSocket"><span class="Identifier">wrapSocket</span></a><span class="Other">(</span><span class="Identifier">ctx</span><span class="Other">:</span> <a href="net.html#SslContext"><span class="Identifier">SslContext</span></a><span class="Other">;</span> <span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Wraps a socket in an SSL context. This function effectively turns <tt class="docutils literal"><span class="pre"><span class="Identifier">socket</span></span></tt> into an SSL socket.</p>
- <p>This must be called on an unconnected socket; an SSL session will be started when the socket is connected.</p>
- <p>FIXME: <strong>Disclaimer</strong>: This code is not well tested, may be very unsafe and prone to security vulnerabilities.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L809" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L809" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="18">
- <h1><a class="toc-backref" href="#18">Templates</a></h1>
- <dl class="item">
- <div id="&=-templates-all">
- <div id="&=.t,Socket,typed">
- <dt><pre><span class="Keyword">template</span> <a href="#%26%3D.t%2CSocket%2Ctyped"><span class="Identifier">`&=`</span></a><span class="Other">(</span><span class="Identifier">socket</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">)</span></pre></dt>
- <dd>
-
- an alias for 'send'.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/net.nim#L1771" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/net.nim#L1771" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:20 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|