home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Doc / libsocket.tex < prev    next >
LaTeX Document  |  1994-09-07  |  11.6 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: libsocket.tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n Module| \sectco|
|00000020| 64 65 7b 73 6f 63 6b 65 | 74 7d 7d 0d 0d 5c 62 69 |de{socke|t}}..\bi|
|00000030| 6d 6f 64 69 6e 64 65 78 | 7b 73 6f 63 6b 65 74 7d |modindex|{socket}|
|00000040| 0d 54 68 69 73 20 6d 6f | 64 75 6c 65 20 70 72 6f |.This mo|dule pro|
|00000050| 76 69 64 65 73 20 61 63 | 63 65 73 73 20 74 6f 20 |vides ac|cess to |
|00000060| 74 68 65 20 42 53 44 20 | 7b 5c 65 6d 20 73 6f 63 |the BSD |{\em soc|
|00000070| 6b 65 74 7d 20 69 6e 74 | 65 72 66 61 63 65 2e 0d |ket} int|erface..|
|00000080| 49 74 20 69 73 20 61 76 | 61 69 6c 61 62 6c 65 20 |It is av|ailable |
|00000090| 6f 6e 20 5c 55 4e 49 58 | 7b 7d 20 73 79 73 74 65 |on \UNIX|{} syste|
|000000a0| 6d 73 20 74 68 61 74 20 | 73 75 70 70 6f 72 74 20 |ms that |support |
|000000b0| 74 68 69 73 20 69 6e 74 | 65 72 66 61 63 65 2e 0d |this int|erface..|
|000000c0| 0d 46 6f 72 20 61 6e 20 | 69 6e 74 72 6f 64 75 63 |.For an |introduc|
|000000d0| 74 69 6f 6e 20 74 6f 20 | 73 6f 63 6b 65 74 20 70 |tion to |socket p|
|000000e0| 72 6f 67 72 61 6d 6d 69 | 6e 67 20 28 69 6e 20 43 |rogrammi|ng (in C|
|000000f0| 29 2c 20 73 65 65 20 74 | 68 65 20 66 6f 6c 6c 6f |), see t|he follo|
|00000100| 77 69 6e 67 0d 70 61 70 | 65 72 73 3a 20 5c 65 6d |wing.pap|ers: \em|
|00000110| 70 68 7b 41 6e 20 49 6e | 74 72 6f 64 75 63 74 6f |ph{An In|troducto|
|00000120| 72 79 20 34 2e 33 42 53 | 44 20 49 6e 74 65 72 70 |ry 4.3BS|D Interp|
|00000130| 72 6f 63 65 73 73 20 43 | 6f 6d 6d 75 6e 69 63 61 |rocess C|ommunica|
|00000140| 74 69 6f 6e 0d 54 75 74 | 6f 72 69 61 6c 7d 2c 20 |tion.Tut|orial}, |
|00000150| 62 79 20 53 74 75 61 72 | 74 20 53 65 63 68 72 65 |by Stuar|t Sechre|
|00000160| 73 74 20 61 6e 64 20 5c | 65 6d 70 68 7b 41 6e 20 |st and \|emph{An |
|00000170| 41 64 76 61 6e 63 65 64 | 20 34 2e 33 42 53 44 20 |Advanced| 4.3BSD |
|00000180| 49 6e 74 65 72 70 72 6f | 63 65 73 73 0d 43 6f 6d |Interpro|cess.Com|
|00000190| 6d 75 6e 69 63 61 74 69 | 6f 6e 20 54 75 74 6f 72 |municati|on Tutor|
|000001a0| 69 61 6c 7d 2c 20 62 79 | 20 53 61 6d 75 65 6c 20 |ial}, by| Samuel |
|000001b0| 4a 2e 20 20 4c 65 66 66 | 6c 65 72 20 65 74 20 61 |J. Leff|ler et a|
|000001c0| 6c 2c 20 62 6f 74 68 20 | 69 6e 20 74 68 65 0d 5c |l, both |in the.\|
|000001d0| 55 4e 49 58 7b 7d 20 50 | 72 6f 67 72 61 6d 6d 65 |UNIX{} P|rogramme|
|000001e0| 72 27 73 20 4d 61 6e 75 | 61 6c 2c 20 53 75 70 70 |r's Manu|al, Supp|
|000001f0| 6c 65 6d 65 6e 74 61 72 | 79 20 44 6f 63 75 6d 65 |lementar|y Docume|
|00000200| 6e 74 73 20 31 20 28 73 | 65 63 74 69 6f 6e 73 20 |nts 1 (s|ections |
|00000210| 50 53 31 3a 37 0d 61 6e | 64 20 50 53 31 3a 38 29 |PS1:7.an|d PS1:8)|
|00000220| 2e 20 20 54 68 65 20 5c | 55 4e 49 58 7b 7d 20 6d |. The \|UNIX{} m|
|00000230| 61 6e 75 61 6c 20 70 61 | 67 65 73 20 66 6f 72 20 |anual pa|ges for |
|00000240| 74 68 65 20 76 61 72 69 | 6f 75 73 20 73 6f 63 6b |the vari|ous sock|
|00000250| 65 74 2d 72 65 6c 61 74 | 65 64 0d 73 79 73 74 65 |et-relat|ed.syste|
|00000260| 6d 20 63 61 6c 6c 73 20 | 61 6c 73 6f 20 61 20 76 |m calls |also a v|
|00000270| 61 6c 75 61 62 6c 65 20 | 73 6f 75 72 63 65 20 6f |aluable |source o|
|00000280| 66 20 69 6e 66 6f 72 6d | 61 74 69 6f 6e 20 6f 6e |f inform|ation on|
|00000290| 20 74 68 65 20 64 65 74 | 61 69 6c 73 20 6f 66 0d | the det|ails of.|
|000002a0| 73 6f 63 6b 65 74 20 73 | 65 6d 61 6e 74 69 63 73 |socket s|emantics|
|000002b0| 2e 0d 0d 54 68 65 20 50 | 79 74 68 6f 6e 20 69 6e |...The P|ython in|
|000002c0| 74 65 72 66 61 63 65 20 | 69 73 20 61 20 73 74 72 |terface |is a str|
|000002d0| 61 69 67 68 74 66 6f 72 | 77 61 72 64 20 74 72 61 |aightfor|ward tra|
|000002e0| 6e 73 6c 69 74 65 72 61 | 74 69 6f 6e 20 6f 66 20 |nslitera|tion of |
|000002f0| 74 68 65 0d 5c 55 4e 49 | 58 7b 7d 20 73 79 73 74 |the.\UNI|X{} syst|
|00000300| 65 6d 20 63 61 6c 6c 20 | 61 6e 64 20 6c 69 62 72 |em call |and libr|
|00000310| 61 72 79 20 69 6e 74 65 | 72 66 61 63 65 20 66 6f |ary inte|rface fo|
|00000320| 72 20 73 6f 63 6b 65 74 | 73 20 74 6f 20 50 79 74 |r socket|s to Pyt|
|00000330| 68 6f 6e 27 73 0d 6f 62 | 6a 65 63 74 2d 6f 72 69 |hon's.ob|ject-ori|
|00000340| 65 6e 74 65 64 20 73 74 | 79 6c 65 3a 20 74 68 65 |ented st|yle: the|
|00000350| 20 5c 63 6f 64 65 7b 73 | 6f 63 6b 65 74 28 29 7d | \code{s|ocket()}|
|00000360| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 74 75 72 6e | functio|n return|
|00000370| 73 20 61 0d 5c 64 66 6e | 7b 73 6f 63 6b 65 74 20 |s a.\dfn|{socket |
|00000380| 6f 62 6a 65 63 74 7d 20 | 77 68 6f 73 65 20 6d 65 |object} |whose me|
|00000390| 74 68 6f 64 73 20 69 6d | 70 6c 65 6d 65 6e 74 20 |thods im|plement |
|000003a0| 74 68 65 20 76 61 72 69 | 6f 75 73 20 73 6f 63 6b |the vari|ous sock|
|000003b0| 65 74 20 73 79 73 74 65 | 6d 0d 63 61 6c 6c 73 2e |et syste|m.calls.|
|000003c0| 20 20 50 61 72 61 6d 65 | 74 65 72 20 74 79 70 65 | Parame|ter type|
|000003d0| 73 20 61 72 65 20 73 6f | 6d 65 77 68 61 74 20 68 |s are so|mewhat h|
|000003e0| 69 67 65 72 2d 6c 65 76 | 65 6c 20 74 68 61 6e 20 |iger-lev|el than |
|000003f0| 69 6e 20 74 68 65 20 43 | 0d 69 6e 74 65 72 66 61 |in the C|.interfa|
|00000400| 63 65 3a 20 61 73 20 77 | 69 74 68 20 5c 63 6f 64 |ce: as w|ith \cod|
|00000410| 65 7b 72 65 61 64 28 29 | 7d 20 61 6e 64 20 5c 63 |e{read()|} and \c|
|00000420| 6f 64 65 7b 77 72 69 74 | 65 28 29 7d 20 6f 70 65 |ode{writ|e()} ope|
|00000430| 72 61 74 69 6f 6e 73 20 | 6f 6e 20 50 79 74 68 6f |rations |on Pytho|
|00000440| 6e 0d 66 69 6c 65 73 2c | 20 62 75 66 66 65 72 20 |n.files,| buffer |
|00000450| 61 6c 6c 6f 63 61 74 69 | 6f 6e 20 6f 6e 20 72 65 |allocati|on on re|
|00000460| 63 65 69 76 65 20 6f 70 | 65 72 61 74 69 6f 6e 73 |ceive op|erations|
|00000470| 20 69 73 20 61 75 74 6f | 6d 61 74 69 63 2c 20 61 | is auto|matic, a|
|00000480| 6e 64 0d 62 75 66 66 65 | 72 20 6c 65 6e 67 74 68 |nd.buffe|r length|
|00000490| 20 69 73 20 69 6d 70 6c | 69 63 69 74 20 6f 6e 20 | is impl|icit on |
|000004a0| 73 65 6e 64 20 6f 70 65 | 72 61 74 69 6f 6e 73 2e |send ope|rations.|
|000004b0| 0d 0d 53 6f 63 6b 65 74 | 20 61 64 64 72 65 73 73 |..Socket| address|
|000004c0| 65 73 20 61 72 65 20 72 | 65 70 72 65 73 65 6e 74 |es are r|epresent|
|000004d0| 65 64 20 61 73 20 61 20 | 73 69 6e 67 6c 65 20 73 |ed as a |single s|
|000004e0| 74 72 69 6e 67 20 66 6f | 72 20 74 68 65 0d 5c 63 |tring fo|r the.\c|
|000004f0| 6f 64 65 7b 41 46 5f 55 | 4e 49 58 7d 20 61 64 64 |ode{AF_U|NIX} add|
|00000500| 72 65 73 73 20 66 61 6d | 69 6c 79 20 61 6e 64 20 |ress fam|ily and |
|00000510| 61 73 20 61 20 70 61 69 | 72 0d 5c 63 6f 64 65 7b |as a pai|r.\code{|
|00000520| 28 5c 76 61 72 7b 68 6f | 73 74 7d 2c 20 5c 76 61 |(\var{ho|st}, \va|
|00000530| 72 7b 70 6f 72 74 7d 29 | 7d 20 66 6f 72 20 74 68 |r{port})|} for th|
|00000540| 65 20 5c 63 6f 64 65 7b | 41 46 5f 49 4e 45 54 7d |e \code{|AF_INET}|
|00000550| 20 61 64 64 72 65 73 73 | 20 66 61 6d 69 6c 79 2c | address| family,|
|00000560| 0d 77 68 65 72 65 20 5c | 76 61 72 7b 68 6f 73 74 |.where \|var{host|
|00000570| 7d 20 69 73 20 61 20 73 | 74 72 69 6e 67 20 72 65 |} is a s|tring re|
|00000580| 70 72 65 73 65 6e 74 69 | 6e 67 0d 65 69 74 68 65 |presenti|ng.eithe|
|00000590| 72 20 61 20 68 6f 73 74 | 6e 61 6d 65 20 69 6e 20 |r a host|name in |
|000005a0| 49 6e 74 65 72 6e 65 74 | 20 64 6f 6d 61 69 6e 20 |Internet| domain |
|000005b0| 6e 6f 74 61 74 69 6f 6e | 20 6c 69 6b 65 0d 5c 63 |notation| like.\c|
|000005c0| 6f 64 65 7b 27 64 61 72 | 69 6e 67 2e 63 77 69 2e |ode{'dar|ing.cwi.|
|000005d0| 6e 6c 27 7d 20 6f 72 20 | 61 6e 20 49 50 20 61 64 |nl'} or |an IP ad|
|000005e0| 64 72 65 73 73 20 6c 69 | 6b 65 20 5c 63 6f 64 65 |dress li|ke \code|
|000005f0| 7b 27 31 30 30 2e 35 30 | 2e 32 30 30 2e 35 27 7d |{'100.50|.200.5'}|
|00000600| 2c 0d 61 6e 64 20 5c 76 | 61 72 7b 70 6f 72 74 7d |,.and \v|ar{port}|
|00000610| 20 69 73 20 61 6e 20 69 | 6e 74 65 67 72 61 6c 20 | is an i|ntegral |
|00000620| 70 6f 72 74 20 6e 75 6d | 62 65 72 2e 20 20 4f 74 |port num|ber. Ot|
|00000630| 68 65 72 20 61 64 64 72 | 65 73 73 20 66 61 6d 69 |her addr|ess fami|
|00000640| 6c 69 65 73 20 61 72 65 | 0d 63 75 72 72 65 6e 74 |lies are|.current|
|00000650| 6c 79 20 6e 6f 74 20 73 | 75 70 70 6f 72 74 65 64 |ly not s|upported|
|00000660| 2e 20 20 54 68 65 20 61 | 64 64 72 65 73 73 20 66 |. The a|ddress f|
|00000670| 6f 72 6d 61 74 20 72 65 | 71 75 69 72 65 64 20 62 |ormat re|quired b|
|00000680| 79 20 61 20 70 61 72 74 | 69 63 75 6c 61 72 0d 73 |y a part|icular.s|
|00000690| 6f 63 6b 65 74 20 6f 62 | 6a 65 63 74 20 69 73 20 |ocket ob|ject is |
|000006a0| 61 75 74 6f 6d 61 74 69 | 63 61 6c 6c 79 20 73 65 |automati|cally se|
|000006b0| 6c 65 63 74 65 64 20 62 | 61 73 65 64 20 6f 6e 20 |lected b|ased on |
|000006c0| 74 68 65 20 61 64 64 72 | 65 73 73 20 66 61 6d 69 |the addr|ess fami|
|000006d0| 6c 79 0d 73 70 65 63 69 | 66 69 65 64 20 77 68 65 |ly.speci|fied whe|
|000006e0| 6e 20 74 68 65 20 73 6f | 63 6b 65 74 20 6f 62 6a |n the so|cket obj|
|000006f0| 65 63 74 20 77 61 73 20 | 63 72 65 61 74 65 64 2e |ect was |created.|
|00000700| 0d 0d 41 6c 6c 20 65 72 | 72 6f 72 73 20 72 61 69 |..All er|rors rai|
|00000710| 73 65 20 65 78 63 65 70 | 74 69 6f 6e 73 2e 20 20 |se excep|tions. |
|00000720| 54 68 65 20 6e 6f 72 6d | 61 6c 20 65 78 63 65 70 |The norm|al excep|
|00000730| 74 69 6f 6e 73 20 66 6f | 72 20 69 6e 76 61 6c 69 |tions fo|r invali|
|00000740| 64 0d 61 72 67 75 6d 65 | 6e 74 20 74 79 70 65 73 |d.argume|nt types|
|00000750| 20 61 6e 64 20 6f 75 74 | 2d 6f 66 2d 6d 65 6d 6f | and out|-of-memo|
|00000760| 72 79 20 63 6f 6e 64 69 | 74 69 6f 6e 73 20 63 61 |ry condi|tions ca|
|00000770| 6e 20 62 65 20 72 61 69 | 73 65 64 3b 20 65 72 72 |n be rai|sed; err|
|00000780| 6f 72 73 0d 72 65 6c 61 | 74 65 64 20 74 6f 20 73 |ors.rela|ted to s|
|00000790| 6f 63 6b 65 74 20 6f 72 | 20 61 64 64 72 65 73 73 |ocket or| address|
|000007a0| 20 73 65 6d 61 6e 74 69 | 63 73 20 72 61 69 73 65 | semanti|cs raise|
|000007b0| 20 74 68 65 20 65 72 72 | 6f 72 20 5c 63 6f 64 65 | the err|or \code|
|000007c0| 7b 73 6f 63 6b 65 74 2e | 65 72 72 6f 72 7d 2e 0d |{socket.|error}..|
|000007d0| 0d 4e 6f 6e 2d 62 6c 6f | 63 6b 69 6e 67 20 61 6e |.Non-blo|cking an|
|000007e0| 64 20 61 73 79 6e 63 68 | 72 6f 6e 6f 75 73 20 6d |d asynch|ronous m|
|000007f0| 6f 64 65 20 61 72 65 20 | 6e 6f 74 20 73 75 70 70 |ode are |not supp|
|00000800| 6f 72 74 65 64 3b 20 73 | 65 65 20 6d 6f 64 75 6c |orted; s|ee modul|
|00000810| 65 0d 5c 63 6f 64 65 7b | 73 65 6c 65 63 74 7d 20 |e.\code{|select} |
|00000820| 66 6f 72 20 61 20 77 61 | 79 20 74 6f 20 64 6f 20 |for a wa|y to do |
|00000830| 6e 6f 6e 2d 62 6c 6f 63 | 6b 69 6e 67 20 73 6f 63 |non-bloc|king soc|
|00000840| 6b 65 74 20 49 2f 4f 2e | 0d 0d 54 68 65 20 6d 6f |ket I/O.|..The mo|
|00000850| 64 75 6c 65 20 5c 63 6f | 64 65 7b 73 6f 63 6b 65 |dule \co|de{socke|
|00000860| 74 7d 20 65 78 70 6f 72 | 74 73 20 74 68 65 20 66 |t} expor|ts the f|
|00000870| 6f 6c 6c 6f 77 69 6e 67 | 20 63 6f 6e 73 74 61 6e |ollowing| constan|
|00000880| 74 73 20 61 6e 64 20 66 | 75 6e 63 74 69 6f 6e 73 |ts and f|unctions|
|00000890| 3a 0d 0d 5c 72 65 6e 65 | 77 63 6f 6d 6d 61 6e 64 |:..\rene|wcommand|
|000008a0| 7b 5c 69 6e 64 65 78 73 | 75 62 69 74 65 6d 7d 7b |{\indexs|ubitem}{|
|000008b0| 28 69 6e 20 6d 6f 64 75 | 6c 65 20 73 6f 63 6b 65 |(in modu|le socke|
|000008c0| 74 29 7d 0d 5c 62 65 67 | 69 6e 7b 65 78 63 64 65 |t)}.\beg|in{excde|
|000008d0| 73 63 7d 7b 65 72 72 6f | 72 7d 0d 54 68 69 73 20 |sc}{erro|r}.This |
|000008e0| 65 78 63 65 70 74 69 6f | 6e 20 69 73 20 72 61 69 |exceptio|n is rai|
|000008f0| 73 65 64 20 66 6f 72 20 | 73 6f 63 6b 65 74 2d 20 |sed for |socket- |
|00000900| 6f 72 20 61 64 64 72 65 | 73 73 2d 72 65 6c 61 74 |or addre|ss-relat|
|00000910| 65 64 20 65 72 72 6f 72 | 73 2e 0d 54 68 65 20 61 |ed error|s..The a|
|00000920| 63 63 6f 6d 70 61 6e 79 | 69 6e 67 20 76 61 6c 75 |ccompany|ing valu|
|00000930| 65 20 69 73 20 65 69 74 | 68 65 72 20 61 20 73 74 |e is eit|her a st|
|00000940| 72 69 6e 67 20 74 65 6c | 6c 69 6e 67 20 77 68 61 |ring tel|ling wha|
|00000950| 74 20 77 65 6e 74 20 77 | 72 6f 6e 67 20 6f 72 20 |t went w|rong or |
|00000960| 61 0d 70 61 69 72 20 5c | 63 6f 64 65 7b 28 5c 76 |a.pair \|code{(\v|
|00000970| 61 72 7b 65 72 72 6e 6f | 7d 2c 20 5c 76 61 72 7b |ar{errno|}, \var{|
|00000980| 73 74 72 69 6e 67 7d 29 | 7d 0d 72 65 70 72 65 73 |string})|}.repres|
|00000990| 65 6e 74 69 6e 67 20 61 | 6e 20 65 72 72 6f 72 20 |enting a|n error |
|000009a0| 72 65 74 75 72 6e 65 64 | 20 62 79 20 61 20 73 79 |returned| by a sy|
|000009b0| 73 74 65 6d 0d 63 61 6c | 6c 2c 20 73 69 6d 69 6c |stem.cal|l, simil|
|000009c0| 61 72 20 74 6f 20 74 68 | 65 20 76 61 6c 75 65 20 |ar to th|e value |
|000009d0| 61 63 63 6f 6d 70 61 6e | 79 69 6e 67 20 5c 63 6f |accompan|ying \co|
|000009e0| 64 65 7b 70 6f 73 69 78 | 2e 65 72 72 6f 72 7d 2e |de{posix|.error}.|
|000009f0| 0d 5c 65 6e 64 7b 65 78 | 63 64 65 73 63 7d 0d 0d |.\end{ex|cdesc}..|
|00000a00| 5c 62 65 67 69 6e 7b 64 | 61 74 61 64 65 73 63 7d |\begin{d|atadesc}|
|00000a10| 7b 41 46 5f 55 4e 49 58 | 7d 0d 5c 64 61 74 61 6c |{AF_UNIX|}.\datal|
|00000a20| 69 6e 65 7b 41 46 5f 49 | 4e 45 54 7d 0d 54 68 65 |ine{AF_I|NET}.The|
|00000a30| 73 65 20 63 6f 6e 73 74 | 61 6e 74 73 20 72 65 70 |se const|ants rep|
|00000a40| 72 65 73 65 6e 74 20 74 | 68 65 20 61 64 64 72 65 |resent t|he addre|
|00000a50| 73 73 20 28 61 6e 64 20 | 70 72 6f 74 6f 63 6f 6c |ss (and |protocol|
|00000a60| 29 20 66 61 6d 69 6c 69 | 65 73 2c 0d 75 73 65 64 |) famili|es,.used|
|00000a70| 20 66 6f 72 20 74 68 65 | 20 66 69 72 73 74 20 61 | for the| first a|
|00000a80| 72 67 75 6d 65 6e 74 20 | 74 6f 20 5c 63 6f 64 65 |rgument |to \code|
|00000a90| 7b 73 6f 63 6b 65 74 28 | 29 7d 2e 20 20 49 66 20 |{socket(|)}. If |
|00000aa0| 74 68 65 20 5c 63 6f 64 | 65 7b 41 46 5f 55 4e 49 |the \cod|e{AF_UNI|
|00000ab0| 58 7d 0d 63 6f 6e 73 74 | 61 6e 74 20 69 73 20 6e |X}.const|ant is n|
|00000ac0| 6f 74 20 64 65 66 69 6e | 65 64 20 74 68 65 6e 20 |ot defin|ed then |
|00000ad0| 74 68 69 73 20 70 72 6f | 74 6f 63 6f 6c 20 69 73 |this pro|tocol is|
|00000ae0| 20 75 6e 73 75 70 70 6f | 72 74 65 64 2e 0d 5c 65 | unsuppo|rted..\e|
|00000af0| 6e 64 7b 64 61 74 61 64 | 65 73 63 7d 0d 0d 5c 62 |nd{datad|esc}..\b|
|00000b00| 65 67 69 6e 7b 64 61 74 | 61 64 65 73 63 7d 7b 53 |egin{dat|adesc}{S|
|00000b10| 4f 43 4b 5f 53 54 52 45 | 41 4d 7d 0d 5c 64 61 74 |OCK_STRE|AM}.\dat|
|00000b20| 61 6c 69 6e 65 7b 53 4f | 43 4b 5f 44 47 52 41 4d |aline{SO|CK_DGRAM|
|00000b30| 7d 0d 5c 64 61 74 61 6c | 69 6e 65 7b 53 4f 43 4b |}.\datal|ine{SOCK|
|00000b40| 5f 52 41 57 7d 0d 5c 64 | 61 74 61 6c 69 6e 65 7b |_RAW}.\d|ataline{|
|00000b50| 53 4f 43 4b 5f 52 44 4d | 7d 0d 5c 64 61 74 61 6c |SOCK_RDM|}.\datal|
|00000b60| 69 6e 65 7b 53 4f 43 4b | 5f 53 45 51 50 41 43 4b |ine{SOCK|_SEQPACK|
|00000b70| 45 54 7d 0d 54 68 65 73 | 65 20 63 6f 6e 73 74 61 |ET}.Thes|e consta|
|00000b80| 6e 74 73 20 72 65 70 72 | 65 73 65 6e 74 20 74 68 |nts repr|esent th|
|00000b90| 65 20 73 6f 63 6b 65 74 | 20 74 79 70 65 73 2c 0d |e socket| types,.|
|00000ba0| 75 73 65 64 20 66 6f 72 | 20 74 68 65 20 73 65 63 |used for| the sec|
|00000bb0| 6f 6e 64 20 61 72 67 75 | 6d 65 6e 74 20 74 6f 20 |ond argu|ment to |
|00000bc0| 5c 63 6f 64 65 7b 73 6f | 63 6b 65 74 28 29 7d 2e |\code{so|cket()}.|
|00000bd0| 0d 28 4f 6e 6c 79 20 5c | 63 6f 64 65 7b 53 4f 43 |.(Only \|code{SOC|
|00000be0| 4b 5f 53 54 52 45 41 4d | 7d 20 61 6e 64 0d 5c 63 |K_STREAM|} and.\c|
|00000bf0| 6f 64 65 7b 53 4f 43 4b | 5f 44 47 52 41 4d 7d 20 |ode{SOCK|_DGRAM} |
|00000c00| 61 70 70 65 61 72 20 74 | 6f 20 62 65 20 67 65 6e |appear t|o be gen|
|00000c10| 65 72 61 6c 6c 79 20 75 | 73 65 66 75 6c 2e 29 0d |erally u|seful.).|
|00000c20| 5c 65 6e 64 7b 64 61 74 | 61 64 65 73 63 7d 0d 0d |\end{dat|adesc}..|
|00000c30| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000c40| 7b 67 65 74 68 6f 73 74 | 62 79 6e 61 6d 65 7d 7b |{gethost|byname}{|
|00000c50| 68 6f 73 74 6e 61 6d 65 | 7d 0d 54 72 61 6e 73 6c |hostname|}.Transl|
|00000c60| 61 74 65 20 61 20 68 6f | 73 74 20 6e 61 6d 65 20 |ate a ho|st name |
|00000c70| 74 6f 20 49 50 20 61 64 | 64 72 65 73 73 20 66 6f |to IP ad|dress fo|
|00000c80| 72 6d 61 74 2e 20 20 54 | 68 65 20 49 50 20 61 64 |rmat. T|he IP ad|
|00000c90| 64 72 65 73 73 20 69 73 | 0d 72 65 74 75 72 6e 65 |dress is|.returne|
|00000ca0| 64 20 61 73 20 61 20 73 | 74 72 69 6e 67 2c 20 65 |d as a s|tring, e|
|00000cb0| 2e 67 2e 2c 20 20 5c 63 | 6f 64 65 7b 27 31 30 30 |.g., \c|ode{'100|
|00000cc0| 2e 35 30 2e 32 30 30 2e | 35 27 7d 2e 20 20 49 66 |.50.200.|5'}. If|
|00000cd0| 20 74 68 65 20 68 6f 73 | 74 20 6e 61 6d 65 0d 69 | the hos|t name.i|
|00000ce0| 73 20 61 6e 20 49 50 20 | 61 64 64 72 65 73 73 20 |s an IP |address |
|00000cf0| 69 74 73 65 6c 66 20 69 | 74 20 69 73 20 72 65 74 |itself i|t is ret|
|00000d00| 75 72 6e 65 64 20 75 6e | 63 68 61 6e 67 65 64 2e |urned un|changed.|
|00000d10| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00000d20| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00000d30| 7d 7b 67 65 74 68 6f 73 | 74 6e 61 6d 65 7d 7b 7d |}{gethos|tname}{}|
|00000d40| 0d 52 65 74 75 72 6e 20 | 61 20 73 74 72 69 6e 67 |.Return |a string|
|00000d50| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 74 68 65 20 | contain|ing the |
|00000d60| 68 6f 73 74 6e 61 6d 65 | 20 6f 66 20 74 68 65 20 |hostname| of the |
|00000d70| 6d 61 63 68 69 6e 65 20 | 77 68 65 72 65 20 0d 74 |machine |where .t|
|00000d80| 68 65 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |he Pytho|n interp|
|00000d90| 72 65 74 65 72 20 69 73 | 20 63 75 72 72 65 6e 74 |reter is| current|
|00000da0| 6c 79 20 65 78 65 63 75 | 74 69 6e 67 2e 20 20 49 |ly execu|ting. I|
|00000db0| 66 20 79 6f 75 20 77 61 | 6e 74 20 74 6f 20 6b 6e |f you wa|nt to kn|
|00000dc0| 6f 77 20 74 68 65 0d 63 | 75 72 72 65 6e 74 20 6d |ow the.c|urrent m|
|00000dd0| 61 63 68 69 6e 65 27 73 | 20 49 50 20 61 64 64 72 |achine's| IP addr|
|00000de0| 65 73 73 2c 20 75 73 65 | 0d 5c 63 6f 64 65 7b 73 |ess, use|.\code{s|
|00000df0| 6f 63 6b 65 74 2e 67 65 | 74 68 6f 73 74 62 79 6e |ocket.ge|thostbyn|
|00000e00| 61 6d 65 28 20 73 6f 63 | 6b 65 74 2e 67 65 74 68 |ame( soc|ket.geth|
|00000e10| 6f 73 74 6e 61 6d 65 28 | 29 20 29 7d 20 69 6e 73 |ostname(|) )} ins|
|00000e20| 74 65 61 64 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |tead..\e|nd{funcd|
|00000e30| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00000e40| 63 64 65 73 63 7d 7b 67 | 65 74 73 65 72 76 62 79 |cdesc}{g|etservby|
|00000e50| 6e 61 6d 65 7d 7b 73 65 | 72 76 69 63 65 6e 61 6d |name}{se|rvicenam|
|00000e60| 65 5c 2c 20 70 72 6f 74 | 6f 63 6f 6c 6e 61 6d 65 |e\, prot|ocolname|
|00000e70| 7d 0d 54 72 61 6e 73 6c | 61 74 65 20 61 6e 20 49 |}.Transl|ate an I|
|00000e80| 6e 74 65 72 6e 65 74 20 | 73 65 72 76 69 63 65 20 |nternet |service |
|00000e90| 6e 61 6d 65 20 61 6e 64 | 20 70 72 6f 74 6f 63 6f |name and| protoco|
|00000ea0| 6c 20 6e 61 6d 65 20 74 | 6f 20 61 20 70 6f 72 74 |l name t|o a port|
|00000eb0| 20 6e 75 6d 62 65 72 0d | 66 6f 72 20 74 68 61 74 | number.|for that|
|00000ec0| 20 73 65 72 76 69 63 65 | 2e 20 20 54 68 65 20 70 | service|. The p|
|00000ed0| 72 6f 74 6f 63 6f 6c 20 | 6e 61 6d 65 20 73 68 6f |rotocol |name sho|
|00000ee0| 75 6c 64 20 62 65 20 5c | 63 6f 64 65 7b 27 74 63 |uld be \|code{'tc|
|00000ef0| 70 27 7d 20 6f 72 0d 5c | 63 6f 64 65 7b 27 75 64 |p'} or.\|code{'ud|
|00000f00| 70 27 7d 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |p'}..\en|d{funcde|
|00000f10| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00000f20| 64 65 73 63 7d 7b 73 6f | 63 6b 65 74 7d 7b 66 61 |desc}{so|cket}{fa|
|00000f30| 6d 69 6c 79 5c 2c 20 74 | 79 70 65 5c 2c 20 70 72 |mily\, t|ype\, pr|
|00000f40| 6f 74 6f 7d 0d 43 72 65 | 61 74 65 20 61 20 6e 65 |oto}.Cre|ate a ne|
|00000f50| 77 20 73 6f 63 6b 65 74 | 20 75 73 69 6e 67 20 74 |w socket| using t|
|00000f60| 68 65 20 67 69 76 65 6e | 20 61 64 64 72 65 73 73 |he given| address|
|00000f70| 20 66 61 6d 69 6c 79 2c | 20 73 6f 63 6b 65 74 20 | family,| socket |
|00000f80| 74 79 70 65 20 61 6e 64 | 0d 70 72 6f 74 6f 63 6f |type and|.protoco|
|00000f90| 6c 20 6e 75 6d 62 65 72 | 2e 20 20 54 68 65 20 61 |l number|. The a|
|00000fa0| 64 64 72 65 73 73 20 66 | 61 6d 69 6c 79 20 73 68 |ddress f|amily sh|
|00000fb0| 6f 75 6c 64 20 62 65 20 | 5c 63 6f 64 65 7b 41 46 |ould be |\code{AF|
|00000fc0| 5f 49 4e 45 54 7d 20 6f | 72 0d 5c 63 6f 64 65 7b |_INET} o|r.\code{|
|00000fd0| 41 46 5f 55 4e 49 58 7d | 2e 20 20 54 68 65 20 73 |AF_UNIX}|. The s|
|00000fe0| 6f 63 6b 65 74 20 74 79 | 70 65 20 73 68 6f 75 6c |ocket ty|pe shoul|
|00000ff0| 64 20 62 65 20 5c 63 6f | 64 65 7b 53 4f 43 4b 5f |d be \co|de{SOCK_|
|00001000| 53 54 52 45 41 4d 7d 2c | 0d 5c 63 6f 64 65 7b 53 |STREAM},|.\code{S|
|00001010| 4f 43 4b 5f 44 47 52 41 | 4d 7d 20 6f 72 20 70 65 |OCK_DGRA|M} or pe|
|00001020| 72 68 61 70 73 20 6f 6e | 65 20 6f 66 20 74 68 65 |rhaps on|e of the|
|00001030| 20 6f 74 68 65 72 20 5c | 73 61 6d 70 7b 53 4f 43 | other \|samp{SOC|
|00001040| 4b 5f 7d 20 63 6f 6e 73 | 74 61 6e 74 73 2e 0d 54 |K_} cons|tants..T|
|00001050| 68 65 20 70 72 6f 74 6f | 63 6f 6c 20 6e 75 6d 62 |he proto|col numb|
|00001060| 65 72 20 69 73 20 75 73 | 75 61 6c 6c 79 20 7a 65 |er is us|ually ze|
|00001070| 72 6f 20 61 6e 64 20 6d | 61 79 20 62 65 20 6f 6d |ro and m|ay be om|
|00001080| 69 74 74 65 64 20 69 6e | 20 74 68 61 74 20 63 61 |itted in| that ca|
|00001090| 73 65 2e 0d 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |se..\end|{funcdes|
|000010a0| 63 7d 0d 0d 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000010b0| 65 73 63 7d 7b 66 72 6f | 6d 66 64 7d 7b 66 64 5c |esc}{fro|mfd}{fd\|
|000010c0| 2c 20 66 61 6d 69 6c 79 | 5c 2c 20 74 79 70 65 5c |, family|\, type\|
|000010d0| 2c 20 70 72 6f 74 6f 7d | 0d 42 75 69 6c 64 20 61 |, proto}|.Build a|
|000010e0| 20 73 6f 63 6b 65 74 20 | 6f 62 6a 65 63 74 20 66 | socket |object f|
|000010f0| 72 6f 6d 20 61 6e 20 65 | 78 69 73 74 69 6e 67 20 |rom an e|xisting |
|00001100| 66 69 6c 65 20 64 65 73 | 63 72 69 70 74 6f 72 20 |file des|criptor |
|00001110| 28 61 6e 20 69 6e 74 65 | 67 65 72 20 61 73 0d 72 |(an inte|ger as.r|
|00001120| 65 74 75 72 6e 65 64 20 | 62 79 20 61 20 66 69 6c |eturned |by a fil|
|00001130| 65 20 6f 62 6a 65 63 74 | 27 73 20 5c 63 6f 64 65 |e object|'s \code|
|00001140| 7b 66 69 6c 65 6e 6f 7d | 20 6d 65 74 68 6f 64 29 |{fileno}| method)|
|00001150| 2e 20 20 41 64 64 72 65 | 73 73 20 66 61 6d 69 6c |. Addre|ss famil|
|00001160| 79 2c 0d 73 6f 63 6b 65 | 74 20 74 79 70 65 20 61 |y,.socke|t type a|
|00001170| 6e 64 20 70 72 6f 74 6f | 63 6f 6c 20 6e 75 6d 62 |nd proto|col numb|
|00001180| 65 72 20 61 72 65 20 61 | 73 20 66 6f 72 20 74 68 |er are a|s for th|
|00001190| 65 20 5c 63 6f 64 65 7b | 73 6f 63 6b 65 74 7d 20 |e \code{|socket} |
|000011a0| 66 75 6e 63 74 69 6f 6e | 0d 61 62 6f 76 65 2e 20 |function|.above. |
|000011b0| 20 54 68 65 20 66 69 6c | 65 20 64 65 73 63 72 69 | The fil|e descri|
|000011c0| 70 74 6f 72 20 73 68 6f | 75 6c 64 20 72 65 66 65 |ptor sho|uld refe|
|000011d0| 72 20 74 6f 20 61 20 73 | 6f 63 6b 65 74 2c 20 62 |r to a s|ocket, b|
|000011e0| 75 74 20 74 68 69 73 20 | 69 73 20 6e 6f 74 0d 63 |ut this |is not.c|
|000011f0| 68 65 63 6b 65 64 20 2d | 2d 2d 20 73 75 62 73 65 |hecked -|-- subse|
|00001200| 71 75 65 6e 74 20 6f 70 | 65 72 61 74 69 6f 6e 73 |quent op|erations|
|00001210| 20 6f 6e 20 74 68 65 20 | 6f 62 6a 65 63 74 20 6d | on the |object m|
|00001220| 61 79 20 66 61 69 6c 20 | 69 66 20 74 68 65 20 66 |ay fail |if the f|
|00001230| 69 6c 65 0d 64 65 73 63 | 72 69 70 74 6f 72 20 69 |ile.desc|riptor i|
|00001240| 73 20 69 6e 76 61 6c 69 | 64 2e 20 20 54 68 69 73 |s invali|d. This|
|00001250| 20 66 75 6e 63 74 69 6f | 6e 20 69 73 20 72 61 72 | functio|n is rar|
|00001260| 65 6c 79 20 6e 65 65 64 | 65 64 2c 20 62 75 74 20 |ely need|ed, but |
|00001270| 63 61 6e 20 62 65 0d 75 | 73 65 64 20 74 6f 20 67 |can be.u|sed to g|
|00001280| 65 74 20 6f 72 20 73 65 | 74 20 73 6f 63 6b 65 74 |et or se|t socket|
|00001290| 20 6f 70 74 69 6f 6e 73 | 20 6f 6e 20 61 20 73 6f | options| on a so|
|000012a0| 63 6b 65 74 20 70 61 73 | 73 65 64 20 74 6f 20 61 |cket pas|sed to a|
|000012b0| 20 70 72 6f 67 72 61 6d | 20 61 73 0d 73 74 61 6e | program| as.stan|
|000012c0| 64 61 72 64 20 69 6e 70 | 75 74 20 6f 72 20 6f 75 |dard inp|ut or ou|
|000012d0| 74 70 75 74 20 28 65 2e | 67 2e 20 61 20 73 65 72 |tput (e.|g. a ser|
|000012e0| 76 65 72 20 73 74 61 72 | 74 65 64 20 62 79 20 74 |ver star|ted by t|
|000012f0| 68 65 20 5c 55 4e 49 58 | 7b 7d 20 69 6e 65 74 0d |he \UNIX|{} inet.|
|00001300| 64 61 65 6d 6f 6e 29 2e | 0d 5c 65 6e 64 7b 66 75 |daemon).|.\end{fu|
|00001310| 6e 63 64 65 73 63 7d 0d | 0d 5c 73 75 62 73 65 63 |ncdesc}.|.\subsec|
|00001320| 74 69 6f 6e 7b 53 6f 63 | 6b 65 74 20 4f 62 6a 65 |tion{Soc|ket Obje|
|00001330| 63 74 20 4d 65 74 68 6f | 64 73 7d 0d 0d 5c 6e 6f |ct Metho|ds}..\no|
|00001340| 69 6e 64 65 6e 74 0d 53 | 6f 63 6b 65 74 20 6f 62 |indent.S|ocket ob|
|00001350| 6a 65 63 74 73 20 68 61 | 76 65 20 74 68 65 20 66 |jects ha|ve the f|
|00001360| 6f 6c 6c 6f 77 69 6e 67 | 20 6d 65 74 68 6f 64 73 |ollowing| methods|
|00001370| 2e 20 20 45 78 63 65 70 | 74 20 66 6f 72 0d 5c 63 |. Excep|t for.\c|
|00001380| 6f 64 65 7b 6d 61 6b 65 | 66 69 6c 65 28 29 7d 20 |ode{make|file()} |
|00001390| 74 68 65 73 65 20 63 6f | 72 72 65 73 70 6f 6e 64 |these co|rrespond|
|000013a0| 20 74 6f 20 5c 55 4e 49 | 58 7b 7d 20 73 79 73 74 | to \UNI|X{} syst|
|000013b0| 65 6d 20 63 61 6c 6c 73 | 20 61 70 70 6c 69 63 61 |em calls| applica|
|000013c0| 62 6c 65 20 74 6f 0d 73 | 6f 63 6b 65 74 73 2e 0d |ble to.s|ockets..|
|000013d0| 0d 5c 72 65 6e 65 77 63 | 6f 6d 6d 61 6e 64 7b 5c |.\renewc|ommand{\|
|000013e0| 69 6e 64 65 78 73 75 62 | 69 74 65 6d 7d 7b 28 73 |indexsub|item}{(s|
|000013f0| 6f 63 6b 65 74 20 6d 65 | 74 68 6f 64 29 7d 0d 5c |ocket me|thod)}.\|
|00001400| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001410| 61 63 63 65 70 74 7d 7b | 7d 0d 41 63 63 65 70 74 |accept}{|}.Accept|
|00001420| 20 61 20 63 6f 6e 6e 65 | 63 74 69 6f 6e 2e 0d 54 | a conne|ction..T|
|00001430| 68 65 20 73 6f 63 6b 65 | 74 20 6d 75 73 74 20 62 |he socke|t must b|
|00001440| 65 20 62 6f 75 6e 64 20 | 74 6f 20 61 6e 20 61 64 |e bound |to an ad|
|00001450| 64 72 65 73 73 20 61 6e | 64 20 6c 69 73 74 65 6e |dress an|d listen|
|00001460| 69 6e 67 20 66 6f 72 20 | 63 6f 6e 6e 65 63 74 69 |ing for |connecti|
|00001470| 6f 6e 73 2e 0d 54 68 65 | 20 72 65 74 75 72 6e 20 |ons..The| return |
|00001480| 76 61 6c 75 65 20 69 73 | 20 61 20 70 61 69 72 20 |value is| a pair |
|00001490| 5c 63 6f 64 65 7b 28 5c | 76 61 72 7b 63 6f 6e 6e |\code{(\|var{conn|
|000014a0| 7d 2c 20 5c 76 61 72 7b | 61 64 64 72 65 73 73 7d |}, \var{|address}|
|000014b0| 29 7d 0d 77 68 65 72 65 | 20 5c 76 61 72 7b 63 6f |)}.where| \var{co|
|000014c0| 6e 6e 7d 20 69 73 20 61 | 20 5c 65 6d 70 68 7b 6e |nn} is a| \emph{n|
|000014d0| 65 77 7d 20 73 6f 63 6b | 65 74 20 6f 62 6a 65 63 |ew} sock|et objec|
|000014e0| 74 20 75 73 61 62 6c 65 | 20 74 6f 20 73 65 6e 64 |t usable| to send|
|000014f0| 20 61 6e 64 0d 72 65 63 | 65 69 76 65 20 64 61 74 | and.rec|eive dat|
|00001500| 61 20 6f 6e 20 74 68 65 | 20 63 6f 6e 6e 65 63 74 |a on the| connect|
|00001510| 69 6f 6e 2c 20 61 6e 64 | 20 5c 76 61 72 7b 61 64 |ion, and| \var{ad|
|00001520| 64 72 65 73 73 7d 20 69 | 73 20 74 68 65 20 61 64 |dress} i|s the ad|
|00001530| 64 72 65 73 73 20 62 6f | 75 6e 64 0d 74 6f 20 74 |dress bo|und.to t|
|00001540| 68 65 20 73 6f 63 6b 65 | 74 20 6f 6e 20 74 68 65 |he socke|t on the|
|00001550| 20 6f 74 68 65 72 20 65 | 6e 64 20 6f 66 20 74 68 | other e|nd of th|
|00001560| 65 20 63 6f 6e 6e 65 63 | 74 69 6f 6e 2e 0d 5c 65 |e connec|tion..\e|
|00001570| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d 0d 5c 62 |nd{funcd|esc}..\b|
|00001580| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 62 |egin{fun|cdesc}{b|
|00001590| 69 6e 64 7d 7b 61 64 64 | 72 65 73 73 7d 0d 42 69 |ind}{add|ress}.Bi|
|000015a0| 6e 64 20 74 68 65 20 73 | 6f 63 6b 65 74 20 74 6f |nd the s|ocket to|
|000015b0| 20 5c 76 61 72 7b 61 64 | 64 72 65 73 73 7d 2e 20 | \var{ad|dress}. |
|000015c0| 20 54 68 65 20 73 6f 63 | 6b 65 74 20 6d 75 73 74 | The soc|ket must|
|000015d0| 20 6e 6f 74 20 61 6c 72 | 65 61 64 79 20 62 65 20 | not alr|eady be |
|000015e0| 62 6f 75 6e 64 2e 0d 28 | 54 68 65 20 66 6f 72 6d |bound..(|The form|
|000015f0| 61 74 20 6f 66 20 5c 76 | 61 72 7b 61 64 64 72 65 |at of \v|ar{addre|
|00001600| 73 73 7d 20 64 65 70 65 | 6e 64 73 20 6f 6e 20 74 |ss} depe|nds on t|
|00001610| 68 65 20 61 64 64 72 65 | 73 73 20 66 61 6d 69 6c |he addre|ss famil|
|00001620| 79 20 2d 2d 20 73 65 65 | 20 61 62 6f 76 65 2e 29 |y -- see| above.)|
|00001630| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00001640| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00001650| 7d 7b 63 6c 6f 73 65 7d | 7b 7d 0d 43 6c 6f 73 65 |}{close}|{}.Close|
|00001660| 20 74 68 65 20 73 6f 63 | 6b 65 74 2e 20 20 41 6c | the soc|ket. Al|
|00001670| 6c 20 66 75 74 75 72 65 | 20 6f 70 65 72 61 74 69 |l future| operati|
|00001680| 6f 6e 73 20 6f 6e 20 74 | 68 65 20 73 6f 63 6b 65 |ons on t|he socke|
|00001690| 74 20 6f 62 6a 65 63 74 | 20 77 69 6c 6c 20 66 61 |t object| will fa|
|000016a0| 69 6c 2e 0d 54 68 65 20 | 72 65 6d 6f 74 65 20 65 |il..The |remote e|
|000016b0| 6e 64 20 77 69 6c 6c 20 | 72 65 63 65 69 76 65 20 |nd will |receive |
|000016c0| 6e 6f 20 6d 6f 72 65 20 | 64 61 74 61 20 28 61 66 |no more |data (af|
|000016d0| 74 65 72 20 71 75 65 75 | 65 64 20 64 61 74 61 20 |ter queu|ed data |
|000016e0| 69 73 20 66 6c 75 73 68 | 65 64 29 2e 0d 53 6f 63 |is flush|ed)..Soc|
|000016f0| 6b 65 74 73 20 61 72 65 | 20 61 75 74 6f 6d 61 74 |kets are| automat|
|00001700| 69 63 61 6c 6c 79 20 63 | 6c 6f 73 65 64 20 77 68 |ically c|losed wh|
|00001710| 65 6e 20 74 68 65 79 20 | 61 72 65 20 67 61 72 62 |en they |are garb|
|00001720| 61 67 65 2d 63 6f 6c 6c | 65 63 74 65 64 2e 0d 5c |age-coll|ected..\|
|00001730| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00001740| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001750| 63 6f 6e 6e 65 63 74 7d | 7b 61 64 64 72 65 73 73 |connect}|{address|
|00001760| 7d 0d 43 6f 6e 6e 65 63 | 74 20 74 6f 20 61 20 72 |}.Connec|t to a r|
|00001770| 65 6d 6f 74 65 20 73 6f | 63 6b 65 74 20 61 74 20 |emote so|cket at |
|00001780| 5c 76 61 72 7b 61 64 64 | 72 65 73 73 7d 2e 0d 28 |\var{add|ress}..(|
|00001790| 54 68 65 20 66 6f 72 6d | 61 74 20 6f 66 20 5c 76 |The form|at of \v|
|000017a0| 61 72 7b 61 64 64 72 65 | 73 73 7d 20 64 65 70 65 |ar{addre|ss} depe|
|000017b0| 6e 64 73 20 6f 6e 20 74 | 68 65 20 61 64 64 72 65 |nds on t|he addre|
|000017c0| 73 73 20 66 61 6d 69 6c | 79 20 2d 2d 20 73 65 65 |ss famil|y -- see|
|000017d0| 20 61 62 6f 76 65 2e 29 | 0d 5c 65 6e 64 7b 66 75 | above.)|.\end{fu|
|000017e0| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000017f0| 66 75 6e 63 64 65 73 63 | 7d 7b 66 69 6c 65 6e 6f |funcdesc|}{fileno|
|00001800| 7d 7b 7d 0d 52 65 74 75 | 72 6e 20 74 68 65 20 73 |}{}.Retu|rn the s|
|00001810| 6f 63 6b 65 74 27 73 20 | 66 69 6c 65 20 64 65 73 |ocket's |file des|
|00001820| 63 72 69 70 74 6f 72 20 | 28 61 20 73 6d 61 6c 6c |criptor |(a small|
|00001830| 20 69 6e 74 65 67 65 72 | 29 2e 20 20 54 68 69 73 | integer|). This|
|00001840| 20 69 73 20 75 73 65 66 | 75 6c 0d 77 69 74 68 20 | is usef|ul.with |
|00001850| 5c 63 6f 64 65 7b 73 65 | 6c 65 63 74 7d 2e 0d 5c |\code{se|lect}..\|
|00001860| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00001870| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001880| 67 65 74 70 65 65 72 6e | 61 6d 65 7d 7b 7d 0d 52 |getpeern|ame}{}.R|
|00001890| 65 74 75 72 6e 20 74 68 | 65 20 72 65 6d 6f 74 65 |eturn th|e remote|
|000018a0| 20 61 64 64 72 65 73 73 | 20 74 6f 20 77 68 69 63 | address| to whic|
|000018b0| 68 20 74 68 65 20 73 6f | 63 6b 65 74 20 69 73 20 |h the so|cket is |
|000018c0| 63 6f 6e 6e 65 63 74 65 | 64 2e 20 20 54 68 69 73 |connecte|d. This|
|000018d0| 20 69 73 0d 75 73 65 66 | 75 6c 20 74 6f 20 66 69 | is.usef|ul to fi|
|000018e0| 6e 64 20 6f 75 74 20 74 | 68 65 20 70 6f 72 74 20 |nd out t|he port |
|000018f0| 6e 75 6d 62 65 72 20 6f | 66 20 61 20 72 65 6d 6f |number o|f a remo|
|00001900| 74 65 20 49 50 20 73 6f | 63 6b 65 74 2c 20 66 6f |te IP so|cket, fo|
|00001910| 72 20 69 6e 73 74 61 6e | 63 65 2e 0d 28 54 68 65 |r instan|ce..(The|
|00001920| 20 66 6f 72 6d 61 74 20 | 6f 66 20 74 68 65 20 61 | format |of the a|
|00001930| 64 64 72 65 73 73 20 72 | 65 74 75 72 6e 65 64 20 |ddress r|eturned |
|00001940| 64 65 70 65 6e 64 73 20 | 6f 6e 20 74 68 65 20 61 |depends |on the a|
|00001950| 64 64 72 65 73 73 20 66 | 61 6d 69 6c 79 20 2d 2d |ddress f|amily --|
|00001960| 0d 73 65 65 20 61 62 6f | 76 65 2e 29 20 20 4f 6e |.see abo|ve.) On|
|00001970| 20 73 6f 6d 65 20 73 79 | 73 74 65 6d 73 20 74 68 | some sy|stems th|
|00001980| 69 73 20 66 75 6e 63 74 | 69 6f 6e 20 69 73 20 6e |is funct|ion is n|
|00001990| 6f 74 20 73 75 70 70 6f | 72 74 65 64 2e 0d 5c 65 |ot suppo|rted..\e|
|000019a0| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d 0d 5c 62 |nd{funcd|esc}..\b|
|000019b0| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 67 |egin{fun|cdesc}{g|
|000019c0| 65 74 73 6f 63 6b 6e 61 | 6d 65 7d 7b 7d 0d 52 65 |etsockna|me}{}.Re|
|000019d0| 74 75 72 6e 20 74 68 65 | 20 73 6f 63 6b 65 74 27 |turn the| socket'|
|000019e0| 73 20 6f 77 6e 20 61 64 | 64 72 65 73 73 2e 20 20 |s own ad|dress. |
|000019f0| 54 68 69 73 20 69 73 20 | 75 73 65 66 75 6c 20 74 |This is |useful t|
|00001a00| 6f 20 66 69 6e 64 20 6f | 75 74 20 74 68 65 20 70 |o find o|ut the p|
|00001a10| 6f 72 74 0d 6e 75 6d 62 | 65 72 20 6f 66 20 61 6e |ort.numb|er of an|
|00001a20| 20 49 50 20 73 6f 63 6b | 65 74 2c 20 66 6f 72 20 | IP sock|et, for |
|00001a30| 69 6e 73 74 61 6e 63 65 | 2e 0d 28 54 68 65 20 66 |instance|..(The f|
|00001a40| 6f 72 6d 61 74 20 6f 66 | 20 74 68 65 20 61 64 64 |ormat of| the add|
|00001a50| 72 65 73 73 20 72 65 74 | 75 72 6e 65 64 20 64 65 |ress ret|urned de|
|00001a60| 70 65 6e 64 73 20 6f 6e | 20 74 68 65 20 61 64 64 |pends on| the add|
|00001a70| 72 65 73 73 20 66 61 6d | 69 6c 79 20 2d 2d 0d 73 |ress fam|ily --.s|
|00001a80| 65 65 20 61 62 6f 76 65 | 2e 29 0d 5c 65 6e 64 7b |ee above|.).\end{|
|00001a90| 66 75 6e 63 64 65 73 63 | 7d 0d 0d 5c 62 65 67 69 |funcdesc|}..\begi|
|00001aa0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 67 65 74 73 |n{funcde|sc}{gets|
|00001ab0| 6f 63 6b 6f 70 74 7d 7b | 6c 65 76 65 6c 5c 2c 20 |ockopt}{|level\, |
|00001ac0| 6f 70 74 6e 61 6d 65 5c | 2c 20 62 75 66 6c 65 6e |optname\|, buflen|
|00001ad0| 7d 0d 52 65 74 75 72 6e | 20 74 68 65 20 76 61 6c |}.Return| the val|
|00001ae0| 75 65 20 6f 66 20 74 68 | 65 20 67 69 76 65 6e 20 |ue of th|e given |
|00001af0| 73 6f 63 6b 65 74 20 6f | 70 74 69 6f 6e 20 28 73 |socket o|ption (s|
|00001b00| 65 65 20 74 68 65 20 5c | 55 4e 49 58 7b 7d 20 6d |ee the \|UNIX{} m|
|00001b10| 61 6e 20 70 61 67 65 0d | 7b 5c 69 74 20 67 65 74 |an page.|{\it get|
|00001b20| 73 6f 63 6b 6f 70 74 7d | 28 32 29 29 2e 20 20 54 |sockopt}|(2)). T|
|00001b30| 68 65 20 6e 65 65 64 65 | 64 20 73 79 6d 62 6f 6c |he neede|d symbol|
|00001b40| 69 63 20 63 6f 6e 73 74 | 61 6e 74 73 20 61 72 65 |ic const|ants are|
|00001b50| 20 64 65 66 69 6e 65 64 | 20 69 6e 20 6d 6f 64 75 | defined| in modu|
|00001b60| 6c 65 0d 53 4f 43 4b 45 | 54 2e 20 20 49 66 20 74 |le.SOCKE|T. If t|
|00001b70| 68 65 20 6f 70 74 69 6f | 6e 61 6c 20 74 68 69 72 |he optio|nal thir|
|00001b80| 64 20 61 72 67 75 6d 65 | 6e 74 20 69 73 20 61 62 |d argume|nt is ab|
|00001b90| 73 65 6e 74 2c 20 61 6e | 20 69 6e 74 65 67 65 72 |sent, an| integer|
|00001ba0| 20 6f 70 74 69 6f 6e 0d | 69 73 20 61 73 73 75 6d | option.|is assum|
|00001bb0| 65 64 20 61 6e 64 20 69 | 74 73 20 69 6e 74 65 67 |ed and i|ts integ|
|00001bc0| 65 72 20 76 61 6c 75 65 | 20 69 73 20 72 65 74 75 |er value| is retu|
|00001bd0| 72 6e 65 64 20 62 79 20 | 74 68 65 20 66 75 6e 63 |rned by |the func|
|00001be0| 74 69 6f 6e 2e 20 20 49 | 66 0d 5c 76 61 72 7b 62 |tion. I|f.\var{b|
|00001bf0| 75 66 6c 65 6e 7d 20 69 | 73 20 70 72 65 73 65 6e |uflen} i|s presen|
|00001c00| 74 2c 20 69 74 20 73 70 | 65 63 69 66 69 65 73 20 |t, it sp|ecifies |
|00001c10| 74 68 65 20 6d 61 78 69 | 6d 75 6d 20 6c 65 6e 67 |the maxi|mum leng|
|00001c20| 74 68 20 6f 66 20 74 68 | 65 20 62 75 66 66 65 72 |th of th|e buffer|
|00001c30| 20 75 73 65 64 0d 74 6f | 20 72 65 63 65 69 76 65 | used.to| receive|
|00001c40| 20 74 68 65 20 6f 70 74 | 69 6f 6e 20 69 6e 2c 20 | the opt|ion in, |
|00001c50| 61 6e 64 20 74 68 69 73 | 20 62 75 66 66 65 72 20 |and this| buffer |
|00001c60| 69 73 20 72 65 74 75 72 | 6e 65 64 20 61 73 20 61 |is retur|ned as a|
|00001c70| 20 73 74 72 69 6e 67 2e | 0d 49 74 27 73 20 75 70 | string.|.It's up|
|00001c80| 20 74 6f 20 74 68 65 20 | 63 61 6c 6c 65 72 20 74 | to the |caller t|
|00001c90| 6f 20 64 65 63 6f 64 65 | 20 74 68 65 20 63 6f 6e |o decode| the con|
|00001ca0| 74 65 6e 74 73 20 6f 66 | 20 74 68 65 20 62 75 66 |tents of| the buf|
|00001cb0| 66 65 72 20 28 73 65 65 | 20 74 68 65 0d 6f 70 74 |fer (see| the.opt|
|00001cc0| 69 6f 6e 61 6c 20 62 75 | 69 6c 74 2d 69 6e 20 6d |ional bu|ilt-in m|
|00001cd0| 6f 64 75 6c 65 20 5c 63 | 6f 64 65 7b 73 74 72 75 |odule \c|ode{stru|
|00001ce0| 63 74 7d 20 66 6f 72 20 | 61 20 77 61 79 20 74 6f |ct} for |a way to|
|00001cf0| 20 64 65 63 6f 64 65 20 | 43 20 73 74 72 75 63 74 | decode |C struct|
|00001d00| 75 72 65 73 0d 65 6e 63 | 6f 64 65 64 20 61 73 20 |ures.enc|oded as |
|00001d10| 73 74 72 69 6e 67 73 29 | 2e 0d 5c 65 6e 64 7b 66 |strings)|..\end{f|
|00001d20| 75 6e 63 64 65 73 63 7d | 0d 0d 5c 62 65 67 69 6e |uncdesc}|..\begin|
|00001d30| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 6c 69 73 74 65 |{funcdes|c}{liste|
|00001d40| 6e 7d 7b 62 61 63 6b 6c | 6f 67 7d 0d 4c 69 73 74 |n}{backl|og}.List|
|00001d50| 65 6e 20 66 6f 72 20 63 | 6f 6e 6e 65 63 74 69 6f |en for c|onnectio|
|00001d60| 6e 73 20 6d 61 64 65 20 | 74 6f 20 74 68 65 20 73 |ns made |to the s|
|00001d70| 6f 63 6b 65 74 2e 0d 54 | 68 65 20 61 72 67 75 6d |ocket..T|he argum|
|00001d80| 65 6e 74 20 73 70 65 63 | 69 66 69 65 73 20 74 68 |ent spec|ifies th|
|00001d90| 65 20 6d 61 78 69 6d 75 | 6d 20 6e 75 6d 62 65 72 |e maximu|m number|
|00001da0| 20 6f 66 20 71 75 65 75 | 65 64 20 63 6f 6e 6e 65 | of queu|ed conne|
|00001db0| 63 74 69 6f 6e 73 20 61 | 6e 64 0d 73 68 6f 75 6c |ctions a|nd.shoul|
|00001dc0| 64 20 62 65 20 61 74 20 | 6c 65 61 73 74 20 31 3b |d be at |least 1;|
|00001dd0| 20 74 68 65 20 6d 61 78 | 69 6d 75 6d 20 76 61 6c | the max|imum val|
|00001de0| 75 65 20 69 73 20 73 79 | 73 74 65 6d 2d 64 65 70 |ue is sy|stem-dep|
|00001df0| 65 6e 64 65 6e 74 2e 0d | 5c 65 6e 64 7b 66 75 6e |endent..|\end{fun|
|00001e00| 63 64 65 73 63 7d 0d 0d | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00001e10| 75 6e 63 64 65 73 63 7d | 7b 6d 61 6b 65 66 69 6c |uncdesc}|{makefil|
|00001e20| 65 7d 7b 6d 6f 64 65 7d | 0d 52 65 74 75 72 6e 20 |e}{mode}|.Return |
|00001e30| 61 20 5c 64 66 6e 7b 66 | 69 6c 65 20 6f 62 6a 65 |a \dfn{f|ile obje|
|00001e40| 63 74 7d 20 61 73 73 6f | 63 69 61 74 65 64 20 77 |ct} asso|ciated w|
|00001e50| 69 74 68 20 74 68 65 20 | 73 6f 63 6b 65 74 2e 0d |ith the |socket..|
|00001e60| 28 46 69 6c 65 20 6f 62 | 6a 65 63 74 73 20 77 65 |(File ob|jects we|
|00001e70| 72 65 20 64 65 73 63 72 | 69 62 65 64 20 65 61 72 |re descr|ibed ear|
|00001e80| 6c 69 65 72 20 75 6e 64 | 65 72 20 42 75 69 6c 74 |lier und|er Built|
|00001e90| 2d 69 6e 20 54 79 70 65 | 73 2e 29 0d 54 68 65 20 |-in Type|s.).The |
|00001ea0| 66 69 6c 65 20 6f 62 6a | 65 63 74 20 72 65 66 65 |file obj|ect refe|
|00001eb0| 72 65 6e 63 65 73 20 61 | 20 5c 63 6f 64 65 7b 64 |rences a| \code{d|
|00001ec0| 75 70 7d 70 65 64 20 76 | 65 72 73 69 6f 6e 20 6f |up}ped v|ersion o|
|00001ed0| 66 20 74 68 65 20 73 6f | 63 6b 65 74 20 66 69 6c |f the so|cket fil|
|00001ee0| 65 0d 64 65 73 63 72 69 | 70 74 6f 72 2c 20 73 6f |e.descri|ptor, so|
|00001ef0| 20 74 68 65 20 66 69 6c | 65 20 6f 62 6a 65 63 74 | the fil|e object|
|00001f00| 20 61 6e 64 20 73 6f 63 | 6b 65 74 20 6f 62 6a 65 | and soc|ket obje|
|00001f10| 63 74 20 6d 61 79 20 62 | 65 20 63 6c 6f 73 65 64 |ct may b|e closed|
|00001f20| 20 6f 72 0d 67 61 72 62 | 61 67 65 2d 63 6f 6c 6c | or.garb|age-coll|
|00001f30| 65 63 74 65 64 20 69 6e | 64 65 70 65 6e 64 65 6e |ected in|dependen|
|00001f40| 74 6c 79 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |tly..\en|d{funcde|
|00001f50| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00001f60| 64 65 73 63 7d 7b 72 65 | 63 76 7d 7b 62 75 66 73 |desc}{re|cv}{bufs|
|00001f70| 69 7a 65 5c 2c 20 66 6c | 61 67 73 7d 0d 52 65 63 |ize\, fl|ags}.Rec|
|00001f80| 65 69 76 65 20 64 61 74 | 61 20 66 72 6f 6d 20 74 |eive dat|a from t|
|00001f90| 68 65 20 73 6f 63 6b 65 | 74 2e 20 20 54 68 65 20 |he socke|t. The |
|00001fa0| 72 65 74 75 72 6e 20 76 | 61 6c 75 65 20 69 73 20 |return v|alue is |
|00001fb0| 61 20 73 74 72 69 6e 67 | 20 72 65 70 72 65 73 65 |a string| represe|
|00001fc0| 6e 74 69 6e 67 0d 74 68 | 65 20 64 61 74 61 20 72 |nting.th|e data r|
|00001fd0| 65 63 65 69 76 65 64 2e | 20 20 54 68 65 20 6d 61 |eceived.| The ma|
|00001fe0| 78 69 6d 75 6d 20 61 6d | 6f 75 6e 74 20 6f 66 20 |ximum am|ount of |
|00001ff0| 64 61 74 61 20 74 6f 20 | 62 65 20 72 65 63 65 69 |data to |be recei|
|00002000| 76 65 64 0d 61 74 20 6f | 6e 63 65 20 69 73 20 73 |ved.at o|nce is s|
|00002010| 70 65 63 69 66 69 65 64 | 20 62 79 20 5c 76 61 72 |pecified| by \var|
|00002020| 7b 62 75 66 73 69 7a 65 | 7d 2e 20 20 53 65 65 20 |{bufsize|}. See |
|00002030| 74 68 65 20 5c 55 4e 49 | 58 7b 7d 20 6d 61 6e 75 |the \UNI|X{} manu|
|00002040| 61 6c 20 70 61 67 65 0d | 66 6f 72 20 74 68 65 20 |al page.|for the |
|00002050| 6d 65 61 6e 69 6e 67 20 | 6f 66 20 74 68 65 20 6f |meaning |of the o|
|00002060| 70 74 69 6f 6e 61 6c 20 | 61 72 67 75 6d 65 6e 74 |ptional |argument|
|00002070| 20 5c 76 61 72 7b 66 6c | 61 67 73 7d 3b 20 69 74 | \var{fl|ags}; it|
|00002080| 20 64 65 66 61 75 6c 74 | 73 20 74 6f 0d 7a 65 72 | default|s to.zer|
|00002090| 6f 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |o..\end{|funcdesc|
|000020a0| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|000020b0| 73 63 7d 7b 72 65 63 76 | 66 72 6f 6d 7d 7b 62 75 |sc}{recv|from}{bu|
|000020c0| 66 73 69 7a 65 7d 0d 52 | 65 63 65 69 76 65 20 64 |fsize}.R|eceive d|
|000020d0| 61 74 61 20 66 72 6f 6d | 20 74 68 65 20 73 6f 63 |ata from| the soc|
|000020e0| 6b 65 74 2e 20 20 54 68 | 65 20 72 65 74 75 72 6e |ket. Th|e return|
|000020f0| 20 76 61 6c 75 65 20 69 | 73 20 61 20 70 61 69 72 | value i|s a pair|
|00002100| 0d 5c 63 6f 64 65 7b 28 | 5c 76 61 72 7b 73 74 72 |.\code{(|\var{str|
|00002110| 69 6e 67 7d 2c 20 5c 76 | 61 72 7b 61 64 64 72 65 |ing}, \v|ar{addre|
|00002120| 73 73 7d 29 7d 20 77 68 | 65 72 65 20 5c 76 61 72 |ss})} wh|ere \var|
|00002130| 7b 73 74 72 69 6e 67 7d | 20 69 73 20 61 20 73 74 |{string}| is a st|
|00002140| 72 69 6e 67 0d 72 65 70 | 72 65 73 65 6e 74 69 6e |ring.rep|resentin|
|00002150| 67 20 74 68 65 20 64 61 | 74 61 20 72 65 63 65 69 |g the da|ta recei|
|00002160| 76 65 64 20 61 6e 64 20 | 5c 76 61 72 7b 61 64 64 |ved and |\var{add|
|00002170| 72 65 73 73 7d 20 69 73 | 20 74 68 65 20 61 64 64 |ress} is| the add|
|00002180| 72 65 73 73 20 6f 66 20 | 74 68 65 0d 73 6f 63 6b |ress of |the.sock|
|00002190| 65 74 20 73 65 6e 64 69 | 6e 67 20 74 68 65 20 64 |et sendi|ng the d|
|000021a0| 61 74 61 2e 0d 28 54 68 | 65 20 66 6f 72 6d 61 74 |ata..(Th|e format|
|000021b0| 20 6f 66 20 5c 76 61 72 | 7b 61 64 64 72 65 73 73 | of \var|{address|
|000021c0| 7d 20 64 65 70 65 6e 64 | 73 20 6f 6e 20 74 68 65 |} depend|s on the|
|000021d0| 20 61 64 64 72 65 73 73 | 20 66 61 6d 69 6c 79 20 | address| family |
|000021e0| 2d 2d 20 73 65 65 20 61 | 62 6f 76 65 2e 29 0d 5c |-- see a|bove.).\|
|000021f0| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00002200| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00002210| 73 65 6e 64 7d 7b 73 74 | 72 69 6e 67 7d 0d 53 65 |send}{st|ring}.Se|
|00002220| 6e 64 20 64 61 74 61 20 | 74 6f 20 74 68 65 20 73 |nd data |to the s|
|00002230| 6f 63 6b 65 74 2e 20 20 | 54 68 65 20 73 6f 63 6b |ocket. |The sock|
|00002240| 65 74 20 6d 75 73 74 20 | 62 65 20 63 6f 6e 6e 65 |et must |be conne|
|00002250| 63 74 65 64 20 74 6f 20 | 61 20 72 65 6d 6f 74 65 |cted to |a remote|
|00002260| 0d 73 6f 63 6b 65 74 2e | 20 20 52 65 74 75 72 6e |.socket.| Return|
|00002270| 20 74 68 65 20 6e 75 6d | 62 65 72 20 6f 66 20 62 | the num|ber of b|
|00002280| 79 74 65 73 20 73 65 6e | 74 2e 0d 5c 65 6e 64 7b |ytes sen|t..\end{|
|00002290| 66 75 6e 63 64 65 73 63 | 7d 0d 0d 5c 62 65 67 69 |funcdesc|}..\begi|
|000022a0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 73 65 6e 64 |n{funcde|sc}{send|
|000022b0| 74 6f 7d 7b 73 74 72 69 | 6e 67 5c 2c 20 61 64 64 |to}{stri|ng\, add|
|000022c0| 72 65 73 73 7d 0d 53 65 | 6e 64 20 64 61 74 61 20 |ress}.Se|nd data |
|000022d0| 74 6f 20 74 68 65 20 73 | 6f 63 6b 65 74 2e 20 20 |to the s|ocket. |
|000022e0| 54 68 65 20 73 6f 63 6b | 65 74 20 73 68 6f 75 6c |The sock|et shoul|
|000022f0| 64 20 6e 6f 74 20 62 65 | 20 63 6f 6e 6e 65 63 74 |d not be| connect|
|00002300| 65 64 20 74 6f 20 61 0d | 72 65 6d 6f 74 65 20 73 |ed to a.|remote s|
|00002310| 6f 63 6b 65 74 2c 20 73 | 69 6e 63 65 20 74 68 65 |ocket, s|ince the|
|00002320| 20 64 65 73 74 69 6e 61 | 74 69 6f 6e 20 73 6f 63 | destina|tion soc|
|00002330| 6b 65 74 20 69 73 20 73 | 70 65 63 69 66 69 65 64 |ket is s|pecified|
|00002340| 20 62 79 0d 5c 63 6f 64 | 65 7b 61 64 64 72 65 73 | by.\cod|e{addres|
|00002350| 73 7d 2e 20 20 52 65 74 | 75 72 6e 20 74 68 65 20 |s}. Ret|urn the |
|00002360| 6e 75 6d 62 65 72 20 6f | 66 20 62 79 74 65 73 20 |number o|f bytes |
|00002370| 73 65 6e 74 2e 0d 28 54 | 68 65 20 66 6f 72 6d 61 |sent..(T|he forma|
|00002380| 74 20 6f 66 20 5c 76 61 | 72 7b 61 64 64 72 65 73 |t of \va|r{addres|
|00002390| 73 7d 20 64 65 70 65 6e | 64 73 20 6f 6e 20 74 68 |s} depen|ds on th|
|000023a0| 65 20 61 64 64 72 65 73 | 73 20 66 61 6d 69 6c 79 |e addres|s family|
|000023b0| 20 2d 2d 20 73 65 65 20 | 61 62 6f 76 65 2e 29 0d | -- see |above.).|
|000023c0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|000023d0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|000023e0| 7b 73 65 74 62 6c 6f 63 | 6b 69 6e 67 7d 7b 66 6c |{setbloc|king}{fl|
|000023f0| 61 67 7d 0d 53 65 74 20 | 62 6c 6f 63 6b 69 6e 67 |ag}.Set |blocking|
|00002400| 20 6f 72 20 6e 6f 6e 2d | 62 6c 6f 63 6b 69 6e 67 | or non-|blocking|
|00002410| 20 6d 6f 64 65 20 6f 66 | 20 74 68 65 20 73 6f 63 | mode of| the soc|
|00002420| 6b 65 74 3a 20 69 66 20 | 5c 76 61 72 7b 66 6c 61 |ket: if |\var{fla|
|00002430| 67 7d 20 69 73 20 30 2c | 0d 74 68 65 20 73 6f 63 |g} is 0,|.the soc|
|00002440| 6b 65 74 20 69 73 20 73 | 65 74 20 74 6f 20 6e 6f |ket is s|et to no|
|00002450| 6e 2d 62 6c 6f 63 6b 69 | 6e 67 2c 20 65 6c 73 65 |n-blocki|ng, else|
|00002460| 20 74 6f 20 62 6c 6f 63 | 6b 69 6e 67 20 6d 6f 64 | to bloc|king mod|
|00002470| 65 2e 20 20 49 6e 69 74 | 69 61 6c 6c 79 0d 61 6c |e. Init|ially.al|
|00002480| 6c 20 73 6f 63 6b 65 74 | 73 20 61 72 65 20 69 6e |l socket|s are in|
|00002490| 20 62 6c 6f 63 6b 69 6e | 67 20 6d 6f 64 65 2e 20 | blockin|g mode. |
|000024a0| 20 49 6e 20 6e 6f 6e 2d | 62 6c 6f 63 6b 69 6e 67 | In non-|blocking|
|000024b0| 20 6d 6f 64 65 2c 20 69 | 66 20 61 0d 5c 63 6f 64 | mode, i|f a.\cod|
|000024c0| 65 7b 72 65 63 76 7d 20 | 63 61 6c 6c 20 64 6f 65 |e{recv} |call doe|
|000024d0| 73 6e 27 74 20 66 69 6e | 64 20 61 6e 79 20 64 61 |sn't fin|d any da|
|000024e0| 74 61 2c 20 6f 72 20 69 | 66 20 61 20 5c 63 6f 64 |ta, or i|f a \cod|
|000024f0| 65 7b 73 65 6e 64 7d 20 | 63 61 6c 6c 20 63 61 6e |e{send} |call can|
|00002500| 27 74 0d 69 6d 6d 65 64 | 69 61 74 65 6c 79 20 64 |'t.immed|iately d|
|00002510| 69 73 70 6f 73 65 20 6f | 66 20 74 68 65 20 64 61 |ispose o|f the da|
|00002520| 74 61 2c 20 61 20 5c 63 | 6f 64 65 7b 73 6f 63 6b |ta, a \c|ode{sock|
|00002530| 65 74 2e 65 72 72 6f 72 | 7d 20 65 78 63 65 70 74 |et.error|} except|
|00002540| 69 6f 6e 20 69 73 0d 72 | 61 69 73 65 64 3b 20 69 |ion is.r|aised; i|
|00002550| 6e 20 62 6c 6f 63 6b 69 | 6e 67 20 6d 6f 64 65 2c |n blocki|ng mode,|
|00002560| 20 74 68 65 20 63 61 6c | 6c 73 20 62 6c 6f 63 6b | the cal|ls block|
|00002570| 20 75 6e 74 69 6c 20 74 | 68 65 79 20 63 61 6e 20 | until t|hey can |
|00002580| 70 72 6f 63 65 65 64 2e | 0d 5c 65 6e 64 7b 66 75 |proceed.|.\end{fu|
|00002590| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000025a0| 66 75 6e 63 64 65 73 63 | 7d 7b 73 65 74 73 6f 63 |funcdesc|}{setsoc|
|000025b0| 6b 6f 70 74 7d 7b 6c 65 | 76 65 6c 5c 2c 20 6f 70 |kopt}{le|vel\, op|
|000025c0| 74 6e 61 6d 65 5c 2c 20 | 76 61 6c 75 65 7d 0d 53 |tname\, |value}.S|
|000025d0| 65 74 20 74 68 65 20 76 | 61 6c 75 65 20 6f 66 20 |et the v|alue of |
|000025e0| 74 68 65 20 67 69 76 65 | 6e 20 73 6f 63 6b 65 74 |the give|n socket|
|000025f0| 20 6f 70 74 69 6f 6e 20 | 28 73 65 65 20 74 68 65 | option |(see the|
|00002600| 20 5c 55 4e 49 58 7b 7d | 20 6d 61 6e 20 70 61 67 | \UNIX{}| man pag|
|00002610| 65 0d 7b 5c 69 74 20 73 | 65 74 73 6f 63 6b 6f 70 |e.{\it s|etsockop|
|00002620| 74 7d 28 32 29 29 2e 20 | 20 54 68 65 20 6e 65 65 |t}(2)). | The nee|
|00002630| 64 65 64 20 73 79 6d 62 | 6f 6c 69 63 20 63 6f 6e |ded symb|olic con|
|00002640| 73 74 61 6e 74 73 20 61 | 72 65 20 64 65 66 69 6e |stants a|re defin|
|00002650| 65 64 20 69 6e 20 6d 6f | 64 75 6c 65 0d 5c 63 6f |ed in mo|dule.\co|
|00002660| 64 65 7b 53 4f 43 4b 45 | 54 7d 2e 20 20 54 68 65 |de{SOCKE|T}. The|
|00002670| 20 76 61 6c 75 65 20 63 | 61 6e 20 62 65 20 61 6e | value c|an be an|
|00002680| 20 69 6e 74 65 67 65 72 | 20 6f 72 20 61 20 73 74 | integer| or a st|
|00002690| 72 69 6e 67 20 72 65 70 | 72 65 73 65 6e 74 69 6e |ring rep|resentin|
|000026a0| 67 20 61 0d 62 75 66 66 | 65 72 2e 20 20 49 6e 20 |g a.buff|er. In |
|000026b0| 74 68 65 20 6c 61 74 74 | 65 72 20 63 61 73 65 20 |the latt|er case |
|000026c0| 69 74 20 69 73 20 75 70 | 20 74 6f 20 74 68 65 20 |it is up| to the |
|000026d0| 63 61 6c 6c 65 72 20 74 | 6f 20 65 6e 73 75 72 65 |caller t|o ensure|
|000026e0| 20 74 68 61 74 20 74 68 | 65 0d 73 74 72 69 6e 67 | that th|e.string|
|000026f0| 20 63 6f 6e 74 61 69 6e | 73 20 74 68 65 20 70 72 | contain|s the pr|
|00002700| 6f 70 65 72 20 62 69 74 | 73 20 28 73 65 65 20 74 |oper bit|s (see t|
|00002710| 68 65 20 6f 70 74 69 6f | 6e 61 6c 20 62 75 69 6c |he optio|nal buil|
|00002720| 74 2d 69 6e 20 6d 6f 64 | 75 6c 65 0d 5c 63 6f 64 |t-in mod|ule.\cod|
|00002730| 65 7b 73 74 72 75 63 74 | 7d 20 66 6f 72 20 61 20 |e{struct|} for a |
|00002740| 77 61 79 20 74 6f 20 65 | 6e 63 6f 64 65 20 43 20 |way to e|ncode C |
|00002750| 73 74 72 75 63 74 75 72 | 65 73 20 61 73 20 73 74 |structur|es as st|
|00002760| 72 69 6e 67 73 29 2e 0d | 5c 65 6e 64 7b 66 75 6e |rings)..|\end{fun|
|00002770| 63 64 65 73 63 7d 0d 0d | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00002780| 75 6e 63 64 65 73 63 7d | 7b 73 68 75 74 64 6f 77 |uncdesc}|{shutdow|
|00002790| 6e 7d 7b 68 6f 77 7d 0d | 53 68 75 74 20 64 6f 77 |n}{how}.|Shut dow|
|000027a0| 6e 20 6f 6e 65 20 6f 72 | 20 62 6f 74 68 20 68 61 |n one or| both ha|
|000027b0| 6c 76 65 73 20 6f 66 20 | 74 68 65 20 63 6f 6e 6e |lves of |the conn|
|000027c0| 65 63 74 69 6f 6e 2e 20 | 20 49 66 20 5c 76 61 72 |ection. | If \var|
|000027d0| 7b 68 6f 77 7d 20 69 73 | 20 5c 63 6f 64 65 7b 30 |{how} is| \code{0|
|000027e0| 7d 2c 0d 66 75 72 74 68 | 65 72 20 72 65 63 65 69 |},.furth|er recei|
|000027f0| 76 65 73 20 61 72 65 20 | 64 69 73 61 6c 6c 6f 77 |ves are |disallow|
|00002800| 65 64 2e 20 20 49 66 20 | 5c 76 61 72 7b 68 6f 77 |ed. If |\var{how|
|00002810| 7d 20 69 73 20 5c 63 6f | 64 65 7b 31 7d 2c 20 66 |} is \co|de{1}, f|
|00002820| 75 72 74 68 65 72 20 73 | 65 6e 64 73 20 61 72 65 |urther s|ends are|
|00002830| 0d 64 69 73 61 6c 6c 6f | 77 65 64 2e 20 20 49 66 |.disallo|wed. If|
|00002840| 20 5c 76 61 72 7b 68 6f | 77 7d 20 69 73 20 5c 63 | \var{ho|w} is \c|
|00002850| 6f 64 65 7b 32 7d 2c 20 | 66 75 72 74 68 65 72 20 |ode{2}, |further |
|00002860| 73 65 6e 64 73 20 61 6e | 64 20 72 65 63 65 69 76 |sends an|d receiv|
|00002870| 65 73 20 61 72 65 0d 64 | 69 73 61 6c 6c 6f 77 65 |es are.d|isallowe|
|00002880| 64 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |d..\end{|funcdesc|
|00002890| 7d 0d 0d 4e 6f 74 65 20 | 74 68 61 74 20 74 68 65 |}..Note |that the|
|000028a0| 72 65 20 61 72 65 20 6e | 6f 20 6d 65 74 68 6f 64 |re are n|o method|
|000028b0| 73 20 5c 63 6f 64 65 7b | 72 65 61 64 28 29 7d 20 |s \code{|read()} |
|000028c0| 6f 72 20 5c 63 6f 64 65 | 7b 77 72 69 74 65 28 29 |or \code|{write()|
|000028d0| 7d 3b 20 75 73 65 0d 5c | 63 6f 64 65 7b 72 65 63 |}; use.\|code{rec|
|000028e0| 76 28 29 7d 20 61 6e 64 | 20 5c 63 6f 64 65 7b 73 |v()} and| \code{s|
|000028f0| 65 6e 64 28 29 7d 20 77 | 69 74 68 6f 75 74 20 5c |end()} w|ithout \|
|00002900| 76 61 72 7b 66 6c 61 67 | 73 7d 20 61 72 67 75 6d |var{flag|s} argum|
|00002910| 65 6e 74 20 69 6e 73 74 | 65 61 64 2e 0d 0d 5c 73 |ent inst|ead...\s|
|00002920| 75 62 73 65 63 74 69 6f | 6e 7b 45 78 61 6d 70 6c |ubsectio|n{Exampl|
|00002930| 65 7d 0d 5c 6e 6f 64 65 | 6e 61 6d 65 7b 53 6f 63 |e}.\node|name{Soc|
|00002940| 6b 65 74 20 45 78 61 6d | 70 6c 65 7d 0d 0d 48 65 |ket Exam|ple}..He|
|00002950| 72 65 20 61 72 65 20 74 | 77 6f 20 6d 69 6e 69 6d |re are t|wo minim|
|00002960| 61 6c 20 65 78 61 6d 70 | 6c 65 20 70 72 6f 67 72 |al examp|le progr|
|00002970| 61 6d 73 20 75 73 69 6e | 67 20 74 68 65 20 54 43 |ams usin|g the TC|
|00002980| 50 2f 49 50 20 70 72 6f | 74 6f 63 6f 6c 3a 20 61 |P/IP pro|tocol: a|
|00002990| 0d 73 65 72 76 65 72 20 | 74 68 61 74 20 65 63 68 |.server |that ech|
|000029a0| 6f 65 73 20 61 6c 6c 20 | 64 61 74 61 20 74 68 61 |oes all |data tha|
|000029b0| 74 20 69 74 20 72 65 63 | 65 69 76 65 73 20 62 61 |t it rec|eives ba|
|000029c0| 63 6b 20 28 73 65 72 76 | 69 63 69 6e 67 20 6f 6e |ck (serv|icing on|
|000029d0| 6c 79 20 6f 6e 65 0d 63 | 6c 69 65 6e 74 29 2c 20 |ly one.c|lient), |
|000029e0| 61 6e 64 20 61 20 63 6c | 69 65 6e 74 20 75 73 69 |and a cl|ient usi|
|000029f0| 6e 67 20 69 74 2e 20 20 | 4e 6f 74 65 20 74 68 61 |ng it. |Note tha|
|00002a00| 74 20 61 20 73 65 72 76 | 65 72 20 6d 75 73 74 20 |t a serv|er must |
|00002a10| 70 65 72 66 6f 72 6d 20 | 74 68 65 0d 73 65 71 75 |perform |the.sequ|
|00002a20| 65 6e 63 65 20 5c 63 6f | 64 65 7b 73 6f 63 6b 65 |ence \co|de{socke|
|00002a30| 74 7d 2c 20 5c 63 6f 64 | 65 7b 62 69 6e 64 7d 2c |t}, \cod|e{bind},|
|00002a40| 20 5c 63 6f 64 65 7b 6c | 69 73 74 65 6e 7d 2c 20 | \code{l|isten}, |
|00002a50| 5c 63 6f 64 65 7b 61 63 | 63 65 70 74 7d 0d 28 70 |\code{ac|cept}.(p|
|00002a60| 6f 73 73 69 62 6c 79 20 | 72 65 70 65 61 74 69 6e |ossibly |repeatin|
|00002a70| 67 20 74 68 65 20 5c 63 | 6f 64 65 7b 61 63 63 65 |g the \c|ode{acce|
|00002a80| 70 74 7d 20 74 6f 20 73 | 65 72 76 69 63 65 20 6d |pt} to s|ervice m|
|00002a90| 6f 72 65 20 74 68 61 6e | 20 6f 6e 65 20 63 6c 69 |ore than| one cli|
|00002aa0| 65 6e 74 29 2c 0d 77 68 | 69 6c 65 20 61 20 63 6c |ent),.wh|ile a cl|
|00002ab0| 69 65 6e 74 20 6f 6e 6c | 79 20 6e 65 65 64 73 20 |ient onl|y needs |
|00002ac0| 74 68 65 20 73 65 71 75 | 65 6e 63 65 20 5c 63 6f |the sequ|ence \co|
|00002ad0| 64 65 7b 73 6f 63 6b 65 | 74 7d 2c 20 5c 63 6f 64 |de{socke|t}, \cod|
|00002ae0| 65 7b 63 6f 6e 6e 65 63 | 74 7d 2e 0d 41 6c 73 6f |e{connec|t}..Also|
|00002af0| 20 6e 6f 74 65 20 74 68 | 61 74 20 74 68 65 20 73 | note th|at the s|
|00002b00| 65 72 76 65 72 20 64 6f | 65 73 20 6e 6f 74 20 5c |erver do|es not \|
|00002b10| 63 6f 64 65 7b 73 65 6e | 64 7d 2f 5c 63 6f 64 65 |code{sen|d}/\code|
|00002b20| 7b 72 65 63 65 69 76 65 | 7d 20 6f 6e 20 74 68 65 |{receive|} on the|
|00002b30| 0d 73 6f 63 6b 65 74 20 | 69 74 20 69 73 20 6c 69 |.socket |it is li|
|00002b40| 73 74 65 6e 69 6e 67 20 | 6f 6e 20 62 75 74 20 6f |stening |on but o|
|00002b50| 6e 20 74 68 65 20 6e 65 | 77 20 73 6f 63 6b 65 74 |n the ne|w socket|
|00002b60| 20 72 65 74 75 72 6e 65 | 64 20 62 79 0d 5c 63 6f | returne|d by.\co|
|00002b70| 64 65 7b 61 63 63 65 70 | 74 7d 2e 0d 0d 5c 62 63 |de{accep|t}...\bc|
|00002b80| 6f 64 65 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |ode\begi|n{verbat|
|00002b90| 69 6d 7d 0d 23 20 45 63 | 68 6f 20 73 65 72 76 65 |im}.# Ec|ho serve|
|00002ba0| 72 20 70 72 6f 67 72 61 | 6d 0d 66 72 6f 6d 20 73 |r progra|m.from s|
|00002bb0| 6f 63 6b 65 74 20 69 6d | 70 6f 72 74 20 2a 0d 48 |ocket im|port *.H|
|00002bc0| 4f 53 54 20 3d 20 27 27 | 20 20 20 20 20 20 20 20 |OST = ''| |
|00002bd0| 20 20 20 20 20 20 20 20 | 20 23 20 53 79 6d 62 6f | | # Symbo|
|00002be0| 6c 69 63 20 6e 61 6d 65 | 20 6d 65 61 6e 69 6e 67 |lic name| meaning|
|00002bf0| 20 74 68 65 20 6c 6f 63 | 61 6c 20 68 6f 73 74 0d | the loc|al host.|
|00002c00| 50 4f 52 54 20 3d 20 35 | 30 30 30 37 20 20 20 20 |PORT = 5|0007 |
|00002c10| 20 20 20 20 20 20 20 20 | 20 20 23 20 41 72 62 69 | | # Arbi|
|00002c20| 74 72 61 72 79 20 6e 6f | 6e 2d 70 72 69 76 69 6c |trary no|n-privil|
|00002c30| 65 67 65 64 20 73 65 72 | 76 65 72 0d 73 20 3d 20 |eged ser|ver.s = |
|00002c40| 73 6f 63 6b 65 74 28 41 | 46 5f 49 4e 45 54 2c 20 |socket(A|F_INET, |
|00002c50| 53 4f 43 4b 5f 53 54 52 | 45 41 4d 29 0d 73 2e 62 |SOCK_STR|EAM).s.b|
|00002c60| 69 6e 64 28 48 4f 53 54 | 2c 20 50 4f 52 54 29 0d |ind(HOST|, PORT).|
|00002c70| 73 2e 6c 69 73 74 65 6e | 28 31 29 0d 63 6f 6e 6e |s.listen|(1).conn|
|00002c80| 2c 20 61 64 64 72 20 3d | 20 73 2e 61 63 63 65 70 |, addr =| s.accep|
|00002c90| 74 28 29 0d 70 72 69 6e | 74 20 27 43 6f 6e 6e 65 |t().prin|t 'Conne|
|00002ca0| 63 74 65 64 20 62 79 27 | 2c 20 61 64 64 72 0d 77 |cted by'|, addr.w|
|00002cb0| 68 69 6c 65 20 31 3a 0d | 20 20 20 20 64 61 74 61 |hile 1:.| data|
|00002cc0| 20 3d 20 63 6f 6e 6e 2e | 72 65 63 76 28 31 30 32 | = conn.|recv(102|
|00002cd0| 34 29 0d 20 20 20 20 69 | 66 20 6e 6f 74 20 64 61 |4). i|f not da|
|00002ce0| 74 61 3a 20 62 72 65 61 | 6b 0d 20 20 20 20 63 6f |ta: brea|k. co|
|00002cf0| 6e 6e 2e 73 65 6e 64 28 | 64 61 74 61 29 0d 63 6f |nn.send(|data).co|
|00002d00| 6e 6e 2e 63 6c 6f 73 65 | 28 29 0d 5c 65 6e 64 7b |nn.close|().\end{|
|00002d10| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00002d20| 0d 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00002d30| 72 62 61 74 69 6d 7d 0d | 23 20 45 63 68 6f 20 63 |rbatim}.|# Echo c|
|00002d40| 6c 69 65 6e 74 20 70 72 | 6f 67 72 61 6d 0d 66 72 |lient pr|ogram.fr|
|00002d50| 6f 6d 20 73 6f 63 6b 65 | 74 20 69 6d 70 6f 72 74 |om socke|t import|
|00002d60| 20 2a 0d 48 4f 53 54 20 | 3d 20 27 64 61 72 69 6e | *.HOST |= 'darin|
|00002d70| 67 2e 63 77 69 2e 6e 6c | 27 20 20 20 20 23 20 54 |g.cwi.nl|' # T|
|00002d80| 68 65 20 72 65 6d 6f 74 | 65 20 68 6f 73 74 0d 50 |he remot|e host.P|
|00002d90| 4f 52 54 20 3d 20 35 30 | 30 30 37 20 20 20 20 20 |ORT = 50|007 |
|00002da0| 20 20 20 20 20 20 20 20 | 20 23 20 54 68 65 20 73 | | # The s|
|00002db0| 61 6d 65 20 70 6f 72 74 | 20 61 73 20 75 73 65 64 |ame port| as used|
|00002dc0| 20 62 79 20 74 68 65 20 | 73 65 72 76 65 72 0d 73 | by the |server.s|
|00002dd0| 20 3d 20 73 6f 63 6b 65 | 74 28 41 46 5f 49 4e 45 | = socke|t(AF_INE|
|00002de0| 54 2c 20 53 4f 43 4b 5f | 53 54 52 45 41 4d 29 0d |T, SOCK_|STREAM).|
|00002df0| 73 2e 63 6f 6e 6e 65 63 | 74 28 48 4f 53 54 2c 20 |s.connec|t(HOST, |
|00002e00| 50 4f 52 54 29 0d 73 2e | 73 65 6e 64 28 27 48 65 |PORT).s.|send('He|
|00002e10| 6c 6c 6f 2c 20 77 6f 72 | 6c 64 27 29 0d 64 61 74 |llo, wor|ld').dat|
|00002e20| 61 20 3d 20 73 2e 72 65 | 63 76 28 31 30 32 34 29 |a = s.re|cv(1024)|
|00002e30| 0d 73 2e 63 6c 6f 73 65 | 28 29 0d 70 72 69 6e 74 |.s.close|().print|
|00002e40| 20 27 52 65 63 65 69 76 | 65 64 27 2c 20 60 64 61 | 'Receiv|ed', `da|
|00002e50| 74 61 60 0d 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |ta`.\end|{verbati|
|00002e60| 6d 7d 5c 65 63 6f 64 65 | 0d |m}\ecode|. |
+--------+-------------------------+-------------------------+--------+--------+