diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 01:00:15 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 01:00:15 +0000 |
| commit | 982781f1464c9b7a8133130433f83dbf1f59a2c0 (patch) | |
| tree | 8f96f9e9fa1e6bef8b8356037986ddc18673cade | |
| parent | 6789b83ff5c15296267f880d3b98cf8a1800c30a (diff) | |
| download | luasocket-982781f1464c9b7a8133130433f83dbf1f59a2c0.tar.gz luasocket-982781f1464c9b7a8133130433f83dbf1f59a2c0.tar.bz2 luasocket-982781f1464c9b7a8133130433f83dbf1f59a2c0.zip | |
LuaSocket 2.0 User's Manual.
| -rw-r--r-- | doc/code.html | 202 | ||||
| -rw-r--r-- | doc/dns.html | 120 | ||||
| -rw-r--r-- | doc/ftp.html | 243 | ||||
| -rw-r--r-- | doc/http.html | 388 | ||||
| -rw-r--r-- | doc/index.html | 212 | ||||
| -rw-r--r-- | doc/introduction.html | 328 | ||||
| -rw-r--r-- | doc/luasocket.png | bin | 0 -> 11732 bytes | |||
| -rw-r--r-- | doc/reference.css | 40 | ||||
| -rw-r--r-- | doc/reference.html | 209 | ||||
| -rw-r--r-- | doc/smtp.html | 228 | ||||
| -rw-r--r-- | doc/stream.html | 173 | ||||
| -rw-r--r-- | doc/tcp.html | 415 | ||||
| -rw-r--r-- | doc/udp.html | 400 | ||||
| -rw-r--r-- | doc/url.html | 265 |
14 files changed, 3223 insertions, 0 deletions
diff --git a/doc/code.html b/doc/code.html new file mode 100644 index 0000000..45fd21a --- /dev/null +++ b/doc/code.html | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=code>Code</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | The <tt>code.lua</tt> module offers routines to convert back and forth | ||
| 40 | some common types of content encoding, including Base 64 and URL | ||
| 41 | escaping. Base 64 is described in | ||
| 42 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC | ||
| 43 | 2045</a>, | ||
| 44 | URL escaping is described in | ||
| 45 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC | ||
| 46 | 2396</a>. | ||
| 47 | </p> | ||
| 48 | |||
| 49 | <!-- base64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 50 | |||
| 51 | <p class=name id="base64"> | ||
| 52 | socket.code.<b>base64(</b>content, single<b>)</b> | ||
| 53 | </p> | ||
| 54 | |||
| 55 | <p class=description> | ||
| 56 | Applies the Base 64 content coding to a string. | ||
| 57 | </p> | ||
| 58 | |||
| 59 | <p class=parameters> | ||
| 60 | <tt>Content</tt> is the string to be encoded. | ||
| 61 | If <tt>single</tt> is set to anything | ||
| 62 | but <tt>nil</tt>, the output is returned as a single | ||
| 63 | line, otherwise the function splits the content into 76 character long | ||
| 64 | lines after encoding. | ||
| 65 | </p> | ||
| 66 | |||
| 67 | <p class=result> | ||
| 68 | The function returns the encoded string. | ||
| 69 | </p> | ||
| 70 | |||
| 71 | <pre class=example> | ||
| 72 | code = socket.code.base64("diego:password") | ||
| 73 | -- code = "ZGllZ286cGFzc3dvcmQ=" | ||
| 74 | </pre> | ||
| 75 | |||
| 76 | <!-- unbase64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 77 | |||
| 78 | <p class=name id="unbase64"> | ||
| 79 | socket.code.<b>unbase64(</b>content<b>)</b> | ||
| 80 | </p> | ||
| 81 | |||
| 82 | <p class=description> | ||
| 83 | Removes the Base 64 content coding from a string. | ||
| 84 | </p> | ||
| 85 | |||
| 86 | <p class=parameters> | ||
| 87 | <tt>Content</tt> is the string to be decoded. | ||
| 88 | </p> | ||
| 89 | |||
| 90 | <p class=result> | ||
| 91 | The function returns the decoded string. | ||
| 92 | </p> | ||
| 93 | |||
| 94 | <!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 95 | |||
| 96 | <p class=name id="escape"> | ||
| 97 | socket.code.<b>escape(</b>content<b>)</b> | ||
| 98 | </p> | ||
| 99 | |||
| 100 | <p class=description> | ||
| 101 | Applies the URL escaping content coding to a string | ||
| 102 | Each byte is encoded as a percent character followed | ||
| 103 | by the two byte hexadecimal representation of its integer | ||
| 104 | value. | ||
| 105 | </p> | ||
| 106 | |||
| 107 | <p class=parameters> | ||
| 108 | <tt>Content</tt> is the string to be encoded. | ||
| 109 | </p> | ||
| 110 | |||
| 111 | <p class=result> | ||
| 112 | The function returns the encoded string. | ||
| 113 | </p> | ||
| 114 | |||
| 115 | <pre class=example> | ||
| 116 | code = socket.code.escape("/#?;") | ||
| 117 | -- code = "%2f%23%3f%3b" | ||
| 118 | </pre> | ||
| 119 | |||
| 120 | <!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 121 | |||
| 122 | <p class=name id="unescape"> | ||
| 123 | socket.code.<b>unescape(</b>content<b>)</b> | ||
| 124 | </p> | ||
| 125 | |||
| 126 | <p class=description> | ||
| 127 | Removes the URL escaping content coding from a string. | ||
| 128 | </p> | ||
| 129 | |||
| 130 | <p class=parameters> | ||
| 131 | <tt>Content</tt> is the string to be decoded. | ||
| 132 | </p> | ||
| 133 | |||
| 134 | <p class=return> | ||
| 135 | The function returns the decoded string. | ||
| 136 | </p> | ||
| 137 | |||
| 138 | <!-- hexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 139 | |||
| 140 | <p class=name id="hexa"> | ||
| 141 | socket.code.<b>hexa(</b>content<b>)</b> | ||
| 142 | </p> | ||
| 143 | |||
| 144 | <p class=description> | ||
| 145 | Applies the hexadecimal content coding to a string. | ||
| 146 | Each byte is encoded as the byte hexadecimal | ||
| 147 | representation of its integer value. <p> | ||
| 148 | </p> | ||
| 149 | |||
| 150 | <p class=parameters> | ||
| 151 | <tt>Content</tt> is the string to be encoded. | ||
| 152 | </p> | ||
| 153 | |||
| 154 | <p class=return> | ||
| 155 | The function returns the encoded string. | ||
| 156 | </p> | ||
| 157 | |||
| 158 | <pre class=example> | ||
| 159 | code = socket.code.hexa("\16\32\255") | ||
| 160 | -- code = "1020ff" | ||
| 161 | </pre> | ||
| 162 | |||
| 163 | <!-- unhexa +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 164 | |||
| 165 | <p class=name id="unhexa"> | ||
| 166 | socket.code.<b>unhexa(</b>content<b>)</b> | ||
| 167 | </p> | ||
| 168 | |||
| 169 | <p class=description> | ||
| 170 | Removes the hexadecimal content coding from a string. | ||
| 171 | </p> | ||
| 172 | |||
| 173 | <p class=parameters> | ||
| 174 | <tt>Content</tt> is the string to be decoded. | ||
| 175 | </p> | ||
| 176 | |||
| 177 | <p class=return> | ||
| 178 | The function returns the decoded string. | ||
| 179 | </p> | ||
| 180 | |||
| 181 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 182 | |||
| 183 | <div class=footer> | ||
| 184 | <hr> | ||
| 185 | <center> | ||
| 186 | <p class=bar> | ||
| 187 | <a href="home.html">home</a> · | ||
| 188 | <a href="home.html#down">download</a> · | ||
| 189 | <a href="introduction.html">introduction</a> · | ||
| 190 | <a href="reference.html">reference</a> | ||
| 191 | </p> | ||
| 192 | <p> | ||
| 193 | <small> | ||
| 194 | Last modified by Diego Nehab on <br> | ||
| 195 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 196 | </small> | ||
| 197 | </p> | ||
| 198 | </center> | ||
| 199 | </div> | ||
| 200 | |||
| 201 | </body> | ||
| 202 | </html> | ||
diff --git a/doc/dns.html b/doc/dns.html new file mode 100644 index 0000000..6abf341 --- /dev/null +++ b/doc/dns.html | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=dns>DNS</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | The following functions can be used to convert between host names and IP | ||
| 40 | addresses. Both functions return <em>all</em> information returned by the | ||
| 41 | resolver in a table of the form: | ||
| 42 | </p> | ||
| 43 | |||
| 44 | <blockquote><tt> | ||
| 45 | resolved = {<br> | ||
| 46 | name = <i>canonic-name</i>,<br> | ||
| 47 | alias = <i>alias-list</i>,<br> | ||
| 48 | ip = <i>ip-address-list</i><br> | ||
| 49 | } | ||
| 50 | </tt> </blockquote> | ||
| 51 | |||
| 52 | <p> | ||
| 53 | Note that the <tt>alias</tt> list can be empty. | ||
| 54 | </p> | ||
| 55 | |||
| 56 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 57 | |||
| 58 | <p class=name id=tohostname> | ||
| 59 | socket.dns.<b>tohostname()</b> | ||
| 60 | </p> | ||
| 61 | |||
| 62 | <p class=description> | ||
| 63 | Converts from IP address to host name. | ||
| 64 | </p> | ||
| 65 | |||
| 66 | <p class=parameters> | ||
| 67 | <tt>Address</tt> can be an IP address or host name. | ||
| 68 | </p> | ||
| 69 | |||
| 70 | <p class=return> | ||
| 71 | The function a string with the canonic host name of the given | ||
| 72 | <tt>address</tt>, followed by a table with all information returned by | ||
| 73 | the resolver. In case of error, the function returns <tt>nil</tt> | ||
| 74 | followed by an error message. | ||
| 75 | </p> | ||
| 76 | |||
| 77 | |||
| 78 | <!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 79 | |||
| 80 | <p class=name id=toip> | ||
| 81 | socket.dns.<b>toip()</b> | ||
| 82 | </p> | ||
| 83 | |||
| 84 | <p class=description> | ||
| 85 | Converts from host name to IP address. | ||
| 86 | </p> | ||
| 87 | |||
| 88 | <p class=parameters> | ||
| 89 | <tt>Address</tt> can be an IP address or host name. | ||
| 90 | </p> | ||
| 91 | |||
| 92 | <p class=return> | ||
| 93 | Returns a string with the first IP address found for <tt>address</tt>, | ||
| 94 | followed by a table with all information returned by the resolver. | ||
| 95 | In case of error, the function returns <tt>nil</tt> followed by an error | ||
| 96 | message. | ||
| 97 | </p> | ||
| 98 | |||
| 99 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 100 | |||
| 101 | <div class=footer> | ||
| 102 | <hr> | ||
| 103 | <center> | ||
| 104 | <p class=bar> | ||
| 105 | <a href="home.html">home</a> · | ||
| 106 | <a href="home.html#down">download</a> · | ||
| 107 | <a href="introduction.html">introduction</a> · | ||
| 108 | <a href="reference.html">reference</a> | ||
| 109 | </p> | ||
| 110 | <p> | ||
| 111 | <small> | ||
| 112 | Last modified by Diego Nehab on <br> | ||
| 113 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 114 | </small> | ||
| 115 | </p> | ||
| 116 | </center> | ||
| 117 | </div> | ||
| 118 | |||
| 119 | </body> | ||
| 120 | </html> | ||
diff --git a/doc/ftp.html b/doc/ftp.html new file mode 100644 index 0000000..8072afe --- /dev/null +++ b/doc/ftp.html | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> | ||
| 2 | |||
| 3 | <head> | ||
| 4 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 5 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 6 | </head> | ||
| 7 | |||
| 8 | <body> | ||
| 9 | |||
| 10 | <!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 11 | |||
| 12 | <div class=header> | ||
| 13 | <hr> | ||
| 14 | <center> | ||
| 15 | <table summary="LuaSocket logo"> | ||
| 16 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 17 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 18 | </a></td></tr> | ||
| 19 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 20 | </td></tr> | ||
| 21 | </table> | ||
| 22 | <p class=bar> | ||
| 23 | <a href="home.html">home</a> · | ||
| 24 | <a href="home.html#download">download</a> · | ||
| 25 | <a href="introduction.html">introduction</a> · | ||
| 26 | <a href="reference.html">reference</a> | ||
| 27 | </p> | ||
| 28 | </center> | ||
| 29 | <hr> | ||
| 30 | </div> | ||
| 31 | |||
| 32 | <!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 33 | |||
| 34 | <h2 id=ftp>FTP</h2> | ||
| 35 | |||
| 36 | <p> | ||
| 37 | FTP (File Transfer Protocol) is a protocol used to transfer files | ||
| 38 | between hosts. The module <tt>ftp.lua</tt> offers simple FTP support, | ||
| 39 | allowing applications to download and upload files, and list directory | ||
| 40 | contents. The implementation conforms to | ||
| 41 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc0959.txt">RFC 959</a>. | ||
| 42 | </p> | ||
| 43 | |||
| 44 | <p> | ||
| 45 | URLs MUST conform to | ||
| 46 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc1738.txt">RFC | ||
| 47 | 1738</a>, that is, an URL is a string in the form: | ||
| 48 | </p> | ||
| 49 | |||
| 50 | <blockquote> | ||
| 51 | <tt> | ||
| 52 | [ftp://][<user>[:<password>]@]<host>[:<port>][/<path>][<i>type</i>=a|i|d]</tt> | ||
| 53 | </blockquote> | ||
| 54 | |||
| 55 | <!-- ftp.get ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 56 | |||
| 57 | <p class=name id=get> | ||
| 58 | socket.ftp.<b>get(</b>url<b>)</b><br> | ||
| 59 | socket.ftp.<b>get{</b><br> | ||
| 60 | url = <i>string</i>,<br> | ||
| 61 | type = <i>string</i>,<br> | ||
| 62 | user = <i>string</i>,<br> | ||
| 63 | password = <i>string</i><br> | ||
| 64 | <b>}</b> | ||
| 65 | </p> | ||
| 66 | |||
| 67 | <p class=description> | ||
| 68 | Downloads an URL from a FTP server. | ||
| 69 | </p> | ||
| 70 | |||
| 71 | <p class=parameters> | ||
| 72 | The function can be called either directly with a <tt>url</tt> | ||
| 73 | or with a <em>request table</em>. | ||
| 74 | Fields passed explicitly in the request table override those | ||
| 75 | present in the <tt>url</tt>. | ||
| 76 | </p> | ||
| 77 | |||
| 78 | <p class=parameters> | ||
| 79 | The parameter <tt>type</tt> accepts values '<tt>a</tt>' (ASCII, the | ||
| 80 | default), '<tt>i</tt>' (binary) or '<tt>d</tt>' (directory listing) and | ||
| 81 | determines the transfer type. If <tt><path></tt> ends with a | ||
| 82 | '<tt>/</tt>' or <tt>type</tt> is '<tt>d</tt>', a directory listing of | ||
| 83 | <tt><path></tt> is returned. If no <tt>user</tt> is provided in the | ||
| 84 | <tt>url</tt> or explicitly, the function tries to log in as user | ||
| 85 | '<tt>anonymous</tt>'. | ||
| 86 | </p> | ||
| 87 | |||
| 88 | <p class=return> | ||
| 89 | If successful, the function returns | ||
| 90 | the file content as a string. In case of error, the function returns | ||
| 91 | <tt>nil</tt> and an error message describing the error. | ||
| 92 | </p> | ||
| 93 | |||
| 94 | <pre class=example> | ||
| 95 | -- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br", | ||
| 96 | -- go to directory "pub/lua" and get file "lua.tar.gz" as binary. | ||
| 97 | f, e = socket.ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua/lua.tar.gz;type=i") | ||
| 98 | |||
| 99 | -- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br", | ||
| 100 | -- go to director "pub" and retrieve directory listing of directory "lua" | ||
| 101 | f, e = socket.ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua;type=d") | ||
| 102 | |||
| 103 | -- Log as user "diego", password "nehab", on server "ftp.tecgraf.puc-rio.br", | ||
| 104 | -- go to directory "tec/luasocket/bin" and retrieve file "luasocket.exe" | ||
| 105 | -- (actually, fails because of wrong password, of course) | ||
| 106 | f, e = socket.ftp.get{ | ||
| 107 | url = "ftp://ftp.tecgraf.puc-rio.br/tec/luasocket/bin/luasocket.exe", | ||
| 108 | user = "diego", | ||
| 109 | password = "nehab", | ||
| 110 | type = "i" | ||
| 111 | } | ||
| 112 | -- f returns nil, and e returns an appropriate error message | ||
| 113 | </pre> | ||
| 114 | |||
| 115 | <!-- get_cb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 116 | |||
| 117 | <p class=name id=get_cb> | ||
| 118 | socket.ftp.<b>get_cb{</b><br> | ||
| 119 | url = <i>string</i>,<br> | ||
| 120 | type = <i>string</i>,<br> | ||
| 121 | content_cb = <i>receive-callback</i>,<br> | ||
| 122 | user = <i>string</i>,<br> | ||
| 123 | password = <i>string</i><br> | ||
| 124 | <b>}</b> | ||
| 125 | </p> | ||
| 126 | |||
| 127 | <p class=description> | ||
| 128 | Same as <a href="#get"><tt>get</tt></a>, but the library returns | ||
| 129 | the content of the downloaded file to the receive callback | ||
| 130 | <tt>content_cb</tt>. | ||
| 131 | </p> | ||
| 132 | |||
| 133 | <p class=note> | ||
| 134 | Note: for more information on callbacks, refer to | ||
| 135 | <a href="stream.html#stream">Streaming with callbacks</a>. | ||
| 136 | </p> | ||
| 137 | |||
| 138 | <!-- put ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 139 | |||
| 140 | <p class=name id=put> | ||
| 141 | socket.ftp.<b>put(</b>url, content<b>)</b><br> | ||
| 142 | socket.ftp.<b>put{</b><br> | ||
| 143 | url = <i>string</i>,<br> | ||
| 144 | content = <i>string</i>,<br> | ||
| 145 | type = <i>string</i>,<br> | ||
| 146 | user = <i>string</i>,<br> | ||
| 147 | password = <i>string</i><br> | ||
| 148 | <b>}</b> | ||
| 149 | </p> | ||
| 150 | |||
| 151 | <p class=description> | ||
| 152 | Upload a file to a FTP server. | ||
| 153 | </p> | ||
| 154 | |||
| 155 | <p class=parameters> | ||
| 156 | The function can be called directly with a | ||
| 157 | <tt>url</tt> and <tt>content</tt> parameters, or with a | ||
| 158 | <em>request table</em>. | ||
| 159 | Values passed explicitly in the request table override those present in | ||
| 160 | the <tt>url</tt>. The parameter <tt>type</tt> accept values | ||
| 161 | '<tt>a</tt>' (ASCII, the default) or '<tt>i</tt>' (binary) and | ||
| 162 | determines the transfer type. If no <tt>user</tt> is provided, the | ||
| 163 | function tries to log in as '<tt>anonymous</tt>'. | ||
| 164 | </p> | ||
| 165 | |||
| 166 | <p class=return> | ||
| 167 | If successful, the function returns 1. In case of error, the | ||
| 168 | function returns <tt>nil</tt> followed by a string describing the error. | ||
| 169 | </p> | ||
| 170 | |||
| 171 | <pre class=example> | ||
| 172 | -- Log as user "anonymous" on server "ftp.free.org" and store file | ||
| 173 | -- "hello" with contents "hello world!", using binary mode for the transfer | ||
| 174 | r, e = socket.ftp.put("ftp://ftp.free.org/hello;type=i", "hello world!\n") | ||
| 175 | |||
| 176 | -- Does exactly the same, but logging in as diego | ||
| 177 | r, e = socket.ftp.put{ | ||
| 178 | url = "ftp://ftp.free.org/hello", | ||
| 179 | type = "i", | ||
| 180 | user = "diego", | ||
| 181 | password = "nehab", | ||
| 182 | content = "hello world\n" | ||
| 183 | } | ||
| 184 | </pre> | ||
| 185 | </blockquote> | ||
| 186 | |||
| 187 | <!-- put_cb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 188 | |||
| 189 | <p class=name id=put_cb> | ||
| 190 | socket.ftp.<b>put_cb{</b><br> | ||
| 191 | url = <i>string</i>,<br> | ||
| 192 | type = <i>string</i>,<br> | ||
| 193 | content_cb = <i>send-callback</i>,<br> | ||
| 194 | user = <i>string</i>,<br> | ||
| 195 | password = <i>string</i><br> | ||
| 196 | <b>}</b> | ||
| 197 | </p> | ||
| 198 | |||
| 199 | <p class=description> | ||
| 200 | Same as <a href="#put"><tt>put</tt></a>, but the | ||
| 201 | library obtains the contents of the file to be uploaded using the send | ||
| 202 | callback <tt>content_cb</tt>. | ||
| 203 | </p> | ||
| 204 | |||
| 205 | <p class=note> | ||
| 206 | Note: for more information on callbacks, refer to | ||
| 207 | <a href="stream.html#stream">Streaming with callbacks</a>. | ||
| 208 | </p> | ||
| 209 | |||
| 210 | <pre class=example> | ||
| 211 | -- Log as user "anonymous" on server "ftp.free.org" and store file | ||
| 212 | -- "hello" with contents of the same file in the current directory, | ||
| 213 | -- using binary mode for the transfer | ||
| 214 | r, e = socket.ftp.put_cb{ | ||
| 215 | url = "ftp://ftp.free.org/hello", | ||
| 216 | type = "i", | ||
| 217 | content_cb = socket.callback.send_file(io.open("hello", "r")) | ||
| 218 | } | ||
| 219 | </pre> | ||
| 220 | </blockquote> | ||
| 221 | |||
| 222 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 223 | |||
| 224 | <div class=footer> | ||
| 225 | <hr> | ||
| 226 | <center> | ||
| 227 | <p class=bar> | ||
| 228 | <a href="home.html">home</a> · | ||
| 229 | <a href="home.html#download">download</a> · | ||
| 230 | <a href="introduction.html">introduction</a> · | ||
| 231 | <a href="reference.html">reference</a> | ||
| 232 | </p> | ||
| 233 | <p> | ||
| 234 | <small> | ||
| 235 | Last modified by Diego Nehab on <br> | ||
| 236 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 237 | </small> | ||
| 238 | </p> | ||
| 239 | </center> | ||
| 240 | </div> | ||
| 241 | |||
| 242 | </body> | ||
| 243 | </html> | ||
diff --git a/doc/http.html b/doc/http.html new file mode 100644 index 0000000..b7469a4 --- /dev/null +++ b/doc/http.html | |||
| @@ -0,0 +1,388 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=http>HTTP</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange | ||
| 40 | information between web-browsers and servers. The <tt>http.lua</tt> | ||
| 41 | module offers support for the client side of the HTTP protocol (i.e., | ||
| 42 | the facilities that would be used by a web-browser implementation). The | ||
| 43 | implementation conforms to the HTTP/1.1 standard, | ||
| 44 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC | ||
| 45 | 2616</a>. | ||
| 46 | </p> | ||
| 47 | |||
| 48 | <p> | ||
| 49 | The module exports functions that provide HTTP functionality in different | ||
| 50 | levels of abstraction, from a simple <a | ||
| 51 | href="#get"><tt>get</tt></a>, to the generic, stream oriented | ||
| 52 | <a href="#request_cb"> <tt>request_cb</tt></a>. | ||
| 53 | </p> | ||
| 54 | |||
| 55 | <p> | ||
| 56 | URLs must conform to | ||
| 57 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc1738.txt">RFC | ||
| 58 | 1738</a>, | ||
| 59 | that is, an URL is a string in the form: | ||
| 60 | </p> | ||
| 61 | |||
| 62 | <blockquote> | ||
| 63 | <pre> | ||
| 64 | [http://][<user>[:<password>]@]<host>[:<port>][/<path>] | ||
| 65 | </pre> | ||
| 66 | </blockquote> | ||
| 67 | |||
| 68 | <p> | ||
| 69 | MIME headers are represented as a Lua table in the form: | ||
| 70 | </p> | ||
| 71 | |||
| 72 | <blockquote> | ||
| 73 | <table summary="MIME headers in Lua table"> | ||
| 74 | <tr><td><tt> | ||
| 75 | headers = {<br> | ||
| 76 | field-1-name = <i>field-1-value</i>,<br> | ||
| 77 | field-2-name = <i>field-2-value</i>,<br> | ||
| 78 | field-3-name = <i>field-3-value</i>, | ||
| 79 | </tt></td></tr> | ||
| 80 | <tr><td align=center><tt> | ||
| 81 | ... | ||
| 82 | </tt></td></tr> | ||
| 83 | <tr><td><tt> | ||
| 84 | field-n-name = <i>field-n-value</i><br> | ||
| 85 | } | ||
| 86 | </tt></td></tr> | ||
| 87 | </table> | ||
| 88 | </blockquote> | ||
| 89 | |||
| 90 | <p> | ||
| 91 | Field names are case insensitive (as specified by the standard) and all | ||
| 92 | functions work with lowercase field names. | ||
| 93 | Field values are left unmodified. | ||
| 94 | </p> | ||
| 95 | |||
| 96 | <p class=note> | ||
| 97 | Note: MIME headers are independent of order. Therefore, there is no problem | ||
| 98 | in representing them in a Lua table. | ||
| 99 | </p> | ||
| 100 | |||
| 101 | <!-- http.get +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 102 | |||
| 103 | <p class=name id=get> | ||
| 104 | socket.http.<b>get(</b>url<b>)</b><br> | ||
| 105 | socket.http.<b>get{</b><br> | ||
| 106 | url = <i>string</i>,<br> | ||
| 107 | headers = <i>header-table</i>,<br> | ||
| 108 | user = <i>string</i>,<br> | ||
| 109 | password = <i>string</i>,<br> | ||
| 110 | stay = <i>bool</i>,<br> | ||
| 111 | <b>}</b> | ||
| 112 | </p> | ||
| 113 | |||
| 114 | <p class=description> | ||
| 115 | Performs the HTTP method <tt>GET</tt>. | ||
| 116 | </p> | ||
| 117 | |||
| 118 | <p class=parameters> | ||
| 119 | The function can be | ||
| 120 | called either directly with a <tt>url</tt> or with a <em>request table</em>. | ||
| 121 | The use of a request table allows complete control over the components of | ||
| 122 | the request. Values passed explicitly as fields of the request table | ||
| 123 | override those given by the <tt>url</tt>. For a description of the fields, | ||
| 124 | see the <a href=#request><tt>request</tt></a> function. | ||
| 125 | </p> | ||
| 126 | |||
| 127 | <p class=return> | ||
| 128 | The function returns the response message body, the mime headers, the | ||
| 129 | status code and an error message (if any). In case of failure, the | ||
| 130 | function returns all information it managed to gather. | ||
| 131 | </p> | ||
| 132 | |||
| 133 | <p class=note> | ||
| 134 | Note: The function is trivially implemented with the use of the | ||
| 135 | <a href="#request"><tt>request</tt></a> function. | ||
| 136 | </p> | ||
| 137 | |||
| 138 | <pre class=example> | ||
| 139 | -- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual | ||
| 140 | -- file from "/luasocket/http.html" | ||
| 141 | b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/luasocket/http.html") | ||
| 142 | |||
| 143 | -- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve | ||
| 144 | -- "~diego/auth/index.html". Fails because authentication is needed. | ||
| 145 | b, h, c, e = socket.http.get("http://www.tecgraf.puc-rio.br/~diego/auth/index.html") | ||
| 146 | -- b returns some useless page telling about the denied access, | ||
| 147 | -- h returns authentication information | ||
| 148 | -- and c returns with value 401 (Authentication Required) | ||
| 149 | |||
| 150 | -- tries to connect to server "wrong.host" to retrieve "/" | ||
| 151 | -- and fails because the host does not exist. | ||
| 152 | b, h, c, e = socket.http.get("http://wrong.host/") | ||
| 153 | -- b, h, c are nil, and e returns with value "host not found" | ||
| 154 | </pre> | ||
| 155 | |||
| 156 | <!-- http.post ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 157 | |||
| 158 | <p class=name id=post> | ||
| 159 | socket.http.<b>post(</b>url, body<b>)</b><br> | ||
| 160 | socket.http.<b>post{</b><br> | ||
| 161 | url = <i>string</i>,<br> | ||
| 162 | headers = <i>header-table</i>,<br> | ||
| 163 | body = <i>string</i>,<br> | ||
| 164 | user = <i>string</i>,<br> | ||
| 165 | password = <i>string</i>,<br> | ||
| 166 | stay = <i>bool</i>,<br> | ||
| 167 | <b>}</b> | ||
| 168 | </p> | ||
| 169 | |||
| 170 | <p class=description> | ||
| 171 | Same as <a href="#get"><tt>get</tt></a>, except | ||
| 172 | that the <tt>POST</tt> method is used and the request | ||
| 173 | message <tt>body</tt> is sent along with the request. | ||
| 174 | </p> | ||
| 175 | |||
| 176 | <p class=note> | ||
| 177 | Note: This function is also trivially implemented with the use of the | ||
| 178 | <a href="#request"><tt>request</tt></a> function. | ||
| 179 | </p> | ||
| 180 | |||
| 181 | <!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 182 | |||
| 183 | <p class=name id=request> | ||
| 184 | socket.http.<b>request{</b><br> | ||
| 185 | method = <i>string</i>,<br> | ||
| 186 | url = <i>string</i>,<br> | ||
| 187 | headers = <i>header-table</i>,<br> | ||
| 188 | body = <i>string</i>,<br> | ||
| 189 | user = <i>string</i>,<br> | ||
| 190 | password = <i>string</i>,<br> | ||
| 191 | stay = <i>string</i>,<br> | ||
| 192 | <b>}</b> | ||
| 193 | </p> | ||
| 194 | |||
| 195 | <p class=description> | ||
| 196 | Performs the generic HTTP request using. | ||
| 197 | </p> | ||
| 198 | |||
| 199 | <p class=parameters> | ||
| 200 | The request uses <tt>method</tt> on <tt>url</tt> | ||
| 201 | sending the request <tt>headers</tt> and request <tt>body</tt> in the | ||
| 202 | request message. If authentication information is provided, the function | ||
| 203 | uses the Basic Authentication Scheme (see <a href="#authentication">note</a>) | ||
| 204 | to retrieve the document. <tt>User</tt> and <tt>password</tt> provided | ||
| 205 | explicitly override those given by the <tt>url</tt>. The <tt>stay</tt> | ||
| 206 | parameter, when set to anything but <tt>nil</tt>, prevents the function | ||
| 207 | from automatically following 301 or 302 server redirect messages. | ||
| 208 | </p> | ||
| 209 | |||
| 210 | <p class=return> | ||
| 211 | The function returns a table with all components of the response message | ||
| 212 | it managed to retrieve. The response table has the following form: | ||
| 213 | </p> | ||
| 214 | |||
| 215 | <blockquote><tt> | ||
| 216 | response = {<br> | ||
| 217 | body = <i>string</i>,<br> | ||
| 218 | headers = <i>header-table</i>,<br> | ||
| 219 | status = <i>string</i>,<br> | ||
| 220 | code = <i>number</i>,<br> | ||
| 221 | error = <i>string</i><br> | ||
| 222 | } | ||
| 223 | </tt></blockquote> | ||
| 224 | |||
| 225 | <p class=return> | ||
| 226 | Even when there was failure (URL not found, for example), the | ||
| 227 | function may succeed retrieving a message body (a web page informing the | ||
| 228 | URL was not found or some other useless page). To make sure the | ||
| 229 | operation was successful, check the returned status <tt>code</tt>. For | ||
| 230 | a list of the possible values and their meanings, refer to <a | ||
| 231 | href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC | ||
| 232 | 2616</a>. | ||
| 233 | </p> | ||
| 234 | |||
| 235 | <pre class=example> | ||
| 236 | -- Requests information about a document, without downloading it. | ||
| 237 | -- Useful, for example, if you want to display a download gauge and need | ||
| 238 | -- to know the size of the document in advance | ||
| 239 | response = socket.http.request { | ||
| 240 | method = "HEAD", | ||
| 241 | url = "http://www.tecgraf.puc-rio.br/~diego" | ||
| 242 | } | ||
| 243 | -- Would return the following headers: | ||
| 244 | -- response.headers = { | ||
| 245 | -- date = "Tue, 18 Sep 2001 20:42:21 GMT", | ||
| 246 | -- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)", | ||
| 247 | -- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT", | ||
| 248 | -- ["content-length"] = 15652, | ||
| 249 | -- ["connection"] = "close", | ||
| 250 | -- ["content-Type"] = "text/html" | ||
| 251 | -- } | ||
| 252 | </pre> | ||
| 253 | </blockquote> | ||
| 254 | |||
| 255 | <p class=note id=authentication> | ||
| 256 | Note: Some URLs are protected by their | ||
| 257 | servers from anonymous download. For those URLs, the server must receive | ||
| 258 | some sort of authentication along with the request or it will deny | ||
| 259 | download and return status "401 Authentication Required". | ||
| 260 | </p> | ||
| 261 | |||
| 262 | <p class=note> | ||
| 263 | The HTTP/1.1 standard defines two authentication methods: the Basic | ||
| 264 | Authentication Scheme and the Digest Authentication Scheme, both | ||
| 265 | explained in detail in | ||
| 266 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2068.txt">RFC 2068</a>. | ||
| 267 | </p> | ||
| 268 | |||
| 269 | <p class=note>The Basic Authentication Scheme sends | ||
| 270 | <tt><user></tt> and | ||
| 271 | <tt><password></tt> unencrypted to the server and is therefore | ||
| 272 | considered unsafe. Unfortunately, by the time of this implementation, | ||
| 273 | the wide majority of servers and browsers support the Basic Scheme only. | ||
| 274 | Therefore, this is the method used by the toolkit whenever | ||
| 275 | authentication is required. | ||
| 276 | </p> | ||
| 277 | |||
| 278 | <pre class=example> | ||
| 279 | -- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve | ||
| 280 | -- "~diego/auth/index.html", using the provided name and password to | ||
| 281 | -- authenticate the request | ||
| 282 | response = socket.http.request{ | ||
| 283 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", | ||
| 284 | user = "diego", | ||
| 285 | password = "password" | ||
| 286 | } | ||
| 287 | |||
| 288 | -- Alternatively, one could fill the appropriate header and authenticate | ||
| 289 | -- the request directly. | ||
| 290 | headers = { | ||
| 291 | authentication = "Basic " .. socket.code.base64("diego:password") | ||
| 292 | } | ||
| 293 | response = socket.http.request { | ||
| 294 | url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", | ||
| 295 | headers = headers | ||
| 296 | } | ||
| 297 | </pre> | ||
| 298 | |||
| 299 | <!-- request_cb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 300 | |||
| 301 | <p class=name id=request_cb> | ||
| 302 | socket.http.<b>request_cb(</b>request, response<b>)</b> | ||
| 303 | </p> | ||
| 304 | |||
| 305 | <p class=description> | ||
| 306 | Performs the generic HTTP request. | ||
| 307 | </p> | ||
| 308 | |||
| 309 | <p class=parameters> | ||
| 310 | The function receives two tables as parameters. The <tt>request</tt> table | ||
| 311 | provides information about the request: | ||
| 312 | </p> | ||
| 313 | |||
| 314 | <blockquote><tt> | ||
| 315 | request = {<br> | ||
| 316 | method = <i>string</i>,<br> | ||
| 317 | url = <i>string</i>,<br> | ||
| 318 | headers = <i>header-table</i>,<br> | ||
| 319 | body_cb = <i>send-callback</i>,<br> | ||
| 320 | user = <i>string</i>,<br> | ||
| 321 | password = <i>string</i>,<br> | ||
| 322 | stay = <i>string</i>,<br> | ||
| 323 | }</tt> | ||
| 324 | </blockquote> | ||
| 325 | |||
| 326 | <p class=parameters> | ||
| 327 | The function uses the HTTP method specified in | ||
| 328 | <tt>request.method</tt> on the URL <tt>request.url</tt>, | ||
| 329 | sending <tt>request.headers</tt> along with the request. The request | ||
| 330 | message body is sent via the send callback <tt>request.body_cb</tt>. | ||
| 331 | If authentication information is provided, the function uses the Basic | ||
| 332 | Authentication Scheme (see <a href="#authentication">note</a>) to | ||
| 333 | retrieve the document. <tt>Request.user</tt> and | ||
| 334 | <tt>request.password</tt> override those given by the | ||
| 335 | <tt>request.url</tt>. The <tt>request.stay</tt> parameter, when set to | ||
| 336 | anything but <tt>nil</tt>, prevents the function from automatically | ||
| 337 | following 301 or 302 server redirect messages. | ||
| 338 | </p> | ||
| 339 | |||
| 340 | <p class=parameters> | ||
| 341 | The <tt>response</tt> table specifies information about the desired | ||
| 342 | response: | ||
| 343 | </p> | ||
| 344 | |||
| 345 | <blockquote><tt> | ||
| 346 | response = {<br> | ||
| 347 | body_cb = <i>receive-callback</i><br> | ||
| 348 | }</tt> | ||
| 349 | </blockquote> | ||
| 350 | |||
| 351 | <p class=return> | ||
| 352 | The function returns the same response table as that returned by the | ||
| 353 | <tt>socket.http.request</tt> function, except the response message body is | ||
| 354 | returned to the receive callback given by the | ||
| 355 | <tt>response.body_cb</tt> field. | ||
| 356 | </p> | ||
| 357 | |||
| 358 | <p class=note> | ||
| 359 | Note: For more information on callbacks, please refer to | ||
| 360 | <a href="stream.html#stream">Streaming with callbacks</a>. | ||
| 361 | </p> | ||
| 362 | |||
| 363 | <p class=note> | ||
| 364 | Note: Method names are case <em>sensitive</em> | ||
| 365 | </p> | ||
| 366 | |||
| 367 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 368 | |||
| 369 | <div class=footer> | ||
| 370 | <hr> | ||
| 371 | <center> | ||
| 372 | <p class=bar> | ||
| 373 | <a href="home.html">home</a> · | ||
| 374 | <a href="home.html#download">download</a> · | ||
| 375 | <a href="introduction.html">introduction</a> · | ||
| 376 | <a href="reference.html">reference</a> | ||
| 377 | </p> | ||
| 378 | <p> | ||
| 379 | <small> | ||
| 380 | Last modified by Diego Nehab on <br> | ||
| 381 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 382 | </small> | ||
| 383 | </p> | ||
| 384 | </center> | ||
| 385 | </div> | ||
| 386 | |||
| 387 | </body> | ||
| 388 | </html> | ||
diff --git a/doc/index.html b/doc/index.html new file mode 100644 index 0000000..46642d2 --- /dev/null +++ b/doc/index.html | |||
| @@ -0,0 +1,212 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language </title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- whatis +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=whatis>What is LuaSocket?</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | LuaSocket is a <a href="http://www.lua.org">Lua</a> extension library | ||
| 40 | that is composed by two parts: a C layer that provides support for the TCP | ||
| 41 | and UDP transport layers, and a set of Lua modules that add support for | ||
| 42 | the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and | ||
| 43 | downloading files) protocols. | ||
| 44 | </p> | ||
| 45 | |||
| 46 | <p> | ||
| 47 | Network support has been implemented so that it is both efficient and | ||
| 48 | simple to use. LuaSocket can be used by any Lua application once it has | ||
| 49 | been properly linked with and initialized by the interpreter running the | ||
| 50 | Lua application. The code has been tested and runs well on several Windows | ||
| 51 | and Unix platforms. | ||
| 52 | </p> | ||
| 53 | |||
| 54 | <p> | ||
| 55 | The library is available under the same | ||
| 56 | <a href="http://www.lua.org/copyright.html"> | ||
| 57 | terms and conditions</a> as the Lua language, the MIT license. The idea is | ||
| 58 | that if you can use Lua in a project, you should also be able to use | ||
| 59 | LuaSocket. | ||
| 60 | </p> | ||
| 61 | |||
| 62 | <p> | ||
| 63 | Copyright © 1999-2003 Tecgraf/PUC-Rio. All rights reserved. <br> | ||
| 64 | Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a> | ||
| 65 | </p> | ||
| 66 | |||
| 67 | <!-- download +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 68 | |||
| 69 | <h2 id=down>Download</h2> | ||
| 70 | |||
| 71 | <p> | ||
| 72 | LuaSocket version 2.0 alpha is now available for download! It is | ||
| 73 | compatible with Lua 5.0 and has been tested on | ||
| 74 | Windows XP, Linux, and Mac OS X. | ||
| 75 | </p> | ||
| 76 | |||
| 77 | <p> | ||
| 78 | The library can be downloaded in source code from the following links: | ||
| 79 | </p> | ||
| 80 | |||
| 81 | <blockquote> | ||
| 82 | <p> | ||
| 83 | <a href="luasocket-2.0-alpha.tar.gz">luasocket-2.0-alpha.tar.gz</a> <br> | ||
| 84 | <a href="luasocket-2.0-alpha.zip">luasocket-2.0-alpha.zip</a> | ||
| 85 | </p> | ||
| 86 | </blockquote> | ||
| 87 | |||
| 88 | <p> | ||
| 89 | Besides the full C and Lua source code for the library, the distribution | ||
| 90 | contains several examples, this user's manual and the test procedures. | ||
| 91 | </p> | ||
| 92 | |||
| 93 | <p> | ||
| 94 | I am also providing a Windows binary for those that want to give | ||
| 95 | LuaSocket a quick try: | ||
| 96 | </p> | ||
| 97 | |||
| 98 | <blockquote> | ||
| 99 | <p> | ||
| 100 | <a href="luasocket-2.0.exe">luasocket-2.0.exe</a> | ||
| 101 | </p> | ||
| 102 | </blockquote> | ||
| 103 | |||
| 104 | <p> | ||
| 105 | This binary has been compiled with the <tt>LUASOCKET_DEBUG</tt> | ||
| 106 | option, and should be able to run the automatic test procedures. | ||
| 107 | </p> | ||
| 108 | |||
| 109 | <!-- whatsnew +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 110 | |||
| 111 | <h2 id=new>What's New</h2> | ||
| 112 | |||
| 113 | <p> | ||
| 114 | Most of the changes for 2.0 happened in the C layer, which | ||
| 115 | has been almost completely rewritten. The code has been ported to Lua 5.0 | ||
| 116 | and greatly improved. There have also been some API changes | ||
| 117 | that made the interface simpler and more consistent. Here are some of | ||
| 118 | the changes that made it into version 2.0: | ||
| 119 | </p> | ||
| 120 | |||
| 121 | <ul> | ||
| 122 | <li> Major C code rewrite. Code is modular and extensible. Hopefully, next | ||
| 123 | versions will include code for local domain sockets, file descriptors, | ||
| 124 | pipes (on Unix) and named pipes (on windows) as a bonus; | ||
| 125 | |||
| 126 | <li> Following the Lua 5.0 trend, all functions provided by the library are | ||
| 127 | in the namespace <tt>socket</tt>. Functions such as | ||
| 128 | send/receive/timeout/close etc do not exist anymore as stand-alone | ||
| 129 | functions. They are now only available as methods of the appropriate | ||
| 130 | objects; | ||
| 131 | |||
| 132 | <li> All functions return a non-nil value as first return value if successful. | ||
| 133 | All functions return whatever could be retrieved followed by error message | ||
| 134 | in case of error. The best way to check for errors is to check for the | ||
| 135 | presence of an error message; | ||
| 136 | |||
| 137 | <li> UDP connected sockets can break association with peer by calling | ||
| 138 | <tt>setpeername</tt> with address '<tt>*</tt>'; | ||
| 139 | |||
| 140 | <li> TCP has been changed to become more uniform. First create an object, | ||
| 141 | then connect or bind if needed, and finally use I/O functions. The | ||
| 142 | <tt>socket.connect</tt> and <tt>socket.bind</tt> functions are still | ||
| 143 | provided for simplicity, but they just call <tt>socket.tcp</tt> followed | ||
| 144 | by the <tt>connect</tt> or <tt>bind</tt> methods; | ||
| 145 | |||
| 146 | <li> Better error messages and parameter checking; | ||
| 147 | |||
| 148 | <li> <tt>socket.sleep</tt> and <tt>socket.time</tt> are now part of the | ||
| 149 | library and are supported. They used to be available only when | ||
| 150 | LUASOCKET_DEBUG was defined, but it turns out they might be useful for | ||
| 151 | applications; | ||
| 152 | |||
| 153 | <li> Socket options interface has been improved and TCP objects also | ||
| 154 | support socket options. | ||
| 155 | |||
| 156 | </ul> | ||
| 157 | |||
| 158 | <!-- incompatible +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 159 | |||
| 160 | <h3 id=incompatible>Incompatibilities with previous versions</h3> | ||
| 161 | |||
| 162 | <ul> | ||
| 163 | <li> The introduction of namespaces affects all programs that use LuaSocket, | ||
| 164 | specially code that relies on global functions. These are no longer | ||
| 165 | available. Note that even the support modules (<tt>http</tt>, <tt>smtp</tt> | ||
| 166 | etc) have been moved to the namespace (i.e. <tt>socket.http</tt>, | ||
| 167 | <tt>socket.smtp</tt> etc); | ||
| 168 | |||
| 169 | <li> WARNING: The new <tt>send</tt>, | ||
| 170 | <tt>sendto</tt>, <tt>setpeername</tt> and <tt>setsockname</tt>, | ||
| 171 | <tt>ftp.put</tt>, <tt>ftp.put_cb</tt> return convention WILL break old code; | ||
| 172 | |||
| 173 | <li> Interface to options has changed; | ||
| 174 | |||
| 175 | <li> <tt>socket.select</tt> refuses tables that have anything that is not | ||
| 176 | an object from the group <tt>select{able}</tt>. This includes even the | ||
| 177 | '<tt>n</tt>' field. Silently ignoring objects was a source of bugs for Lua | ||
| 178 | programs. | ||
| 179 | </ul> | ||
| 180 | |||
| 181 | <!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 182 | |||
| 183 | <h2 id=old>Old Versions</h2> | ||
| 184 | |||
| 185 | <p> | ||
| 186 | All previous versions of the LuaSocket library can be downloaded | ||
| 187 | <a href="http://www.tecgraf.puc-rio.br/luasocket/old">here</a>. Although | ||
| 188 | these versions are no longer supported, they are still available for | ||
| 189 | those that have compatibility issues. | ||
| 190 | </p> | ||
| 191 | |||
| 192 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 193 | |||
| 194 | <div class=footer> | ||
| 195 | <hr> | ||
| 196 | <center> | ||
| 197 | <p class=bar> | ||
| 198 | <a href="home.html#down">download</a> · | ||
| 199 | <a href="introduction.html">introduction</a> · | ||
| 200 | <a href="reference.html">reference</a> | ||
| 201 | </p> | ||
| 202 | <p> | ||
| 203 | <small> | ||
| 204 | Last modified by Diego Nehab on <br> | ||
| 205 | Sun Aug 10 01:36:26 PDT 2003 | ||
| 206 | </small> | ||
| 207 | </p> | ||
| 208 | </center> | ||
| 209 | </div> | ||
| 210 | |||
| 211 | </body> | ||
| 212 | </html> | ||
diff --git a/doc/introduction.html b/doc/introduction.html new file mode 100644 index 0000000..7adf45b --- /dev/null +++ b/doc/introduction.html | |||
| @@ -0,0 +1,328 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- introduction +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2>Introduction</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | Communication in LuaSocket is performed via I/O objects. These can | ||
| 40 | represent different network domains. Currently, support is | ||
| 41 | provided for TCP and UDP, but there is work in progress to implement SSL, | ||
| 42 | Local Domain, Pipes, File Descriptors etc. I/O objects provide a standard | ||
| 43 | interface to I/O across different domains and operating systems. | ||
| 44 | LuaSocket 2.0 has been rewritten from scratch to simplify the future | ||
| 45 | addition new domains. | ||
| 46 | </p> | ||
| 47 | |||
| 48 | <p> | ||
| 49 | The LuaSocket API was designed with two goals in mind. First, users | ||
| 50 | experienced with the C API to sockets should feel comfortable using LuaSocket. | ||
| 51 | Second, the simplicity and the feel of the Lua language should be | ||
| 52 | preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified. | ||
| 53 | </p> | ||
| 54 | |||
| 55 | <p> | ||
| 56 | One of the simplifications is the timeout control | ||
| 57 | mechanism. As in C, all I/O operations are blocking by default. For | ||
| 58 | example, the <a href=tcp.html#send><tt>send</tt></a>, | ||
| 59 | <a href=tcp.html#receive><tt>receive</tt></a> and | ||
| 60 | <a href=tcp.html#accept><tt>accept</tt></a> methods | ||
| 61 | of the TCP domain will block the caller application until | ||
| 62 | the operation is completed (if ever!). However, with a call to the | ||
| 63 | <a href=tcp.html#settimeout><tt>settimeout</tt></a> | ||
| 64 | method, an application can specify upper limits on | ||
| 65 | the time it can be blocked by LuaSocket (the "<tt>total</tt>" timeout), on | ||
| 66 | the time LuaSocket can internally be blocked by any OS call (the | ||
| 67 | "<tt>block</tt>" timeout) or a combination of the two. Each LuaSocket | ||
| 68 | call might perform several OS calls, so that the two timeout values are | ||
| 69 | <em>not</em> equivalent. | ||
| 70 | </p> | ||
| 71 | |||
| 72 | <p> | ||
| 73 | Another important difference is the receive pattern capability. | ||
| 74 | Applications can read data from stream domains (such as TCP) | ||
| 75 | line by line, block by block, or until the connection is closed. | ||
| 76 | All I/O reads are buffered and the performance differences between | ||
| 77 | different receive patterns are negligible. | ||
| 78 | </p> | ||
| 79 | |||
| 80 | <p> | ||
| 81 | Finally, the host name resolution is transparent, meaning that most | ||
| 82 | functions and methods accept both IP addresses and host names. In case a | ||
| 83 | host name is given, the library queries the system's resolver and | ||
| 84 | tries the main returned IP address. Note that direct use of IP addresses | ||
| 85 | is more efficient, of course. The | ||
| 86 | <a href=dns.html#toip><tt>toip</tt></a> | ||
| 87 | and <a href=dns.html#tohostname><tt>tohostname</tt></a> | ||
| 88 | functions from the DNS module are provided to convert between host names and IP addresses. | ||
| 89 | </p> | ||
| 90 | |||
| 91 | <p> | ||
| 92 | Previous versions of LuaSocket provided global functions for operating on | ||
| 93 | I/O objects. To give the library a Lua 5.0 feel, these have been eliminated | ||
| 94 | from LuaSocket 2.0. I/O operations are only available as methods of the | ||
| 95 | corresponding I/O objects. Naturally, different I/O objects accept | ||
| 96 | different operations. The core functionality for TCP and UDP objects is | ||
| 97 | introduced in the following sections, following a few words about | ||
| 98 | initialization. | ||
| 99 | </p> | ||
| 100 | |||
| 101 | <!-- initializing +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 102 | |||
| 103 | <h3>Initializing the library</h3> | ||
| 104 | |||
| 105 | <p> | ||
| 106 | Beginning with version 2.0 and following the Lua 5.0 trend, all LuaSocket | ||
| 107 | functionality is defined inside a table (or rather a namespace) stored with | ||
| 108 | the global name <tt>socket</tt>. To have this table created and its | ||
| 109 | contents made available to a Lua script, the interpreter running the script | ||
| 110 | must be linked to the LuaSocket library, and to whatever libraries the | ||
| 111 | host OS requires for network access (Windows requires ws2_32.lib, for | ||
| 112 | instance). LuaSocket is initialized in the | ||
| 113 | Lua state given as the argument to the function | ||
| 114 | <tt>luaopen_socket</tt>, the only C function exported by the library. | ||
| 115 | After initialization, the scripts are free to use all LuaSocket API. | ||
| 116 | </p> | ||
| 117 | |||
| 118 | <!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 119 | |||
| 120 | <h3 id=tcp>TCP</h3> | ||
| 121 | |||
| 122 | <p> | ||
| 123 | TCP (Transfer Control Protocol) is reliable stream protocol. In other | ||
| 124 | words, applications communicating through TCP can send and receive data as | ||
| 125 | an error free stream of bytes. Data is split in one end and | ||
| 126 | reassembled transparently on the other end. There are no boundaries in | ||
| 127 | the data transfers. The library allows users to read data from the | ||
| 128 | sockets in several different granularity: patterns are available for | ||
| 129 | lines, arbitrary sized blocks or "read up to connection closed", all with | ||
| 130 | good performance. | ||
| 131 | </p> | ||
| 132 | |||
| 133 | <p> | ||
| 134 | The library distinguishes three types of TCP sockets: master, client and server sockets. | ||
| 135 | </p> | ||
| 136 | |||
| 137 | <p> | ||
| 138 | Master sockets are newly created TCP sockets returned by the function | ||
| 139 | <a href=tcp.html#tcp><tt>socket.tcp</tt></a>. A master socket is | ||
| 140 | transformed into a server socket | ||
| 141 | after it is associated with a <em>local</em> address by a call to the | ||
| 142 | <a href=tcp.html#bind><tt>bind</tt></a> method. Conversely, it | ||
| 143 | can be changed into a client socket with the method | ||
| 144 | <a href=tcp.html#connect><tt>connect</tt></a>, | ||
| 145 | that associates it with a <em>remote</em> address. | ||
| 146 | </p> | ||
| 147 | |||
| 148 | <p> | ||
| 149 | On server sockets, applications can use the | ||
| 150 | <a href=tcp.html#accept><tt>accept</tt></a> method | ||
| 151 | to wait for a client connection. Once a connection is established, a | ||
| 152 | client socket object is returned representing this connection. The | ||
| 153 | other methods available for server socket objects are | ||
| 154 | <a href=tcp.html#getsockname><tt>getsockname</tt></a>, | ||
| 155 | <a href=tcp.html#setoption><tt>setoption</tt></a>, | ||
| 156 | <a href=tcp.html#settimeout><tt>settimeout</tt></a> and | ||
| 157 | <a href=tcp.html#close><tt>close</tt></a>. | ||
| 158 | </p> | ||
| 159 | |||
| 160 | <p> | ||
| 161 | Client sockets are used to exchange data between two applications over | ||
| 162 | the Internet. Applications can call the methods | ||
| 163 | <a href=tcp.html#send><tt>send</tt></a> and | ||
| 164 | <a href=tcp.html#receive><tt>receive</tt></a> | ||
| 165 | to send and receive data. The other methods | ||
| 166 | available for client socket objects are | ||
| 167 | <a href=tcp.html#getsockname><tt>getsockname</tt></a>, | ||
| 168 | <a href=tcp.html#getpeername><tt>getpeername</tt></a>, | ||
| 169 | <a href=tcp.html#setoption><tt>setoption</tt></a>, | ||
| 170 | <a href=tcp.html#settimeout><tt>settimeout</tt></a> and | ||
| 171 | <a href=tcp.html#close><tt>close</tt></a>. | ||
| 172 | </p> | ||
| 173 | |||
| 174 | <p> | ||
| 175 | Example: | ||
| 176 | </p> | ||
| 177 | <blockquote> | ||
| 178 | <p> | ||
| 179 | A simple echo server, using LuaSocket. The program binds to an ephemeral | ||
| 180 | port (one that is chosen by the operating system) on the local host and | ||
| 181 | awaits client connections on that port. When a connection is established, | ||
| 182 | the program reads a line from the remote end and sends it back, closing | ||
| 183 | the connection immediately after. You can test it using the telnet | ||
| 184 | program. | ||
| 185 | </p> | ||
| 186 | |||
| 187 | <pre class=example> | ||
| 188 | -- create a new TCP object | ||
| 189 | server, err = socket.tcp() | ||
| 190 | assert(server, err) | ||
| 191 | -- bind it to the local host, at any port | ||
| 192 | ret, err = server:bind("*", 0) | ||
| 193 | assert(ret, err) | ||
| 194 | -- find out which port the OS chose for us | ||
| 195 | ip, port = server:getsockname() | ||
| 196 | -- print a message informing what's up | ||
| 197 | print("Please telnet to localhost on port " .. port) | ||
| 198 | print("After connecting, you have 10s to enter a line to be echoed") | ||
| 199 | -- loop forever waiting for clients | ||
| 200 | while 1 do | ||
| 201 | -- wait for a conection from any client | ||
| 202 | client, err = server:accept() | ||
| 203 | -- make sure we don't block waiting for this client's line | ||
| 204 | client:settimeout(10) | ||
| 205 | -- receive the line | ||
| 206 | line, err = client:receive() | ||
| 207 | -- if there was no error, send it back to the client | ||
| 208 | if not err then | ||
| 209 | client:send(line .. "\n") | ||
| 210 | end | ||
| 211 | -- done with client, close the object | ||
| 212 | client:close() | ||
| 213 | end | ||
| 214 | </pre> | ||
| 215 | </blockquote> | ||
| 216 | |||
| 217 | <!-- udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 218 | |||
| 219 | <h3 id=udp>UDP</h3> | ||
| 220 | |||
| 221 | <p> | ||
| 222 | UDP (User Datagram Protocol) is a non-reliable datagram protocol. In | ||
| 223 | other words, applications communicating through UDP send and receive | ||
| 224 | data as independent blocks, which are not guaranteed to reach the other | ||
| 225 | end. Even when they do reach the other end, they are not guaranteed to be | ||
| 226 | error free. Data transfers are atomic, one datagram at a time. Reading | ||
| 227 | only part of a datagram discards the rest, so that the following read | ||
| 228 | operation will act on the next datagram. The advantages are in | ||
| 229 | simplicity (no connection setup) and performance (no error checking or | ||
| 230 | error correction). | ||
| 231 | </p> | ||
| 232 | |||
| 233 | <p> | ||
| 234 | An UDP socket object is created by the | ||
| 235 | <a href=udp.html#udp><tt>socket.udp</tt></a> function. UDP | ||
| 236 | sockets do not need to be connected before use. The method | ||
| 237 | <a href=udp.html#sendto><tt>sendto</tt></a> | ||
| 238 | can be used immediately after creation to | ||
| 239 | send a datagram to IP address and port. Host names are not allowed | ||
| 240 | because performing name resolution for each packet would be forbiddingly | ||
| 241 | slow. Methods | ||
| 242 | <a href=udp.html#receive><tt>receive</tt></a> and | ||
| 243 | <a href=udp.html#receivefrom><tt>receivefrom</tt></a> | ||
| 244 | can be used to retrieve datagrams, the latter returning the IP and port of | ||
| 245 | the sender as extra return values (thus being slightly less | ||
| 246 | efficient). | ||
| 247 | </p> | ||
| 248 | |||
| 249 | <p> | ||
| 250 | When communication is performed repeatedly with a single peer, an | ||
| 251 | application should call the | ||
| 252 | <a href=udp.html#setpeername><tt>setpeername</tt></a> method to specify a | ||
| 253 | permanent partner. Methods | ||
| 254 | <a href=udp.html#sendto><tt>sendto</tt></a> and | ||
| 255 | <a href=udp.html#receivefrom><tt>receivefrom</tt></a> | ||
| 256 | can no longer be used, but the method | ||
| 257 | <a href=udp.html#send><tt>send</tt></a> can be used to send data | ||
| 258 | directly to the peer, and the method | ||
| 259 | <a href=udp.html#receive><tt>receive</tt></a> | ||
| 260 | will only return datagrams originating | ||
| 261 | from that peer. There is about 30% performance gain due to this practice. | ||
| 262 | </p> | ||
| 263 | |||
| 264 | <p> | ||
| 265 | To associate an UDP socket with a local address, an application calls the | ||
| 266 | <a href=udp.html#setsockname><tt>setsockname</tt></a> | ||
| 267 | method <em>before</em> sending any datagrams. Otherwise, the socket is | ||
| 268 | automatically bound to an ephemeral address before the first data | ||
| 269 | transmission and once bound the local address cannot be changed. | ||
| 270 | The other methods available for UDP sockets are | ||
| 271 | <a href=udp.html#getpeername><tt>getpeername</tt></a>, | ||
| 272 | <a href=udp.html#getsockname><tt>getsockname</tt></a>, | ||
| 273 | <a href=udp.html#settimeout><tt>settimeout</tt></a>, | ||
| 274 | <a href=udp.html#setoption><tt>setoption</tt></a> and | ||
| 275 | <a href=udp.html#close><tt>close</tt></a>. | ||
| 276 | </p> | ||
| 277 | |||
| 278 | <p> | ||
| 279 | Example: | ||
| 280 | </p> | ||
| 281 | <blockquote> | ||
| 282 | <p> | ||
| 283 | A simple daytime client, using LuaSocket. The program connects to a remote | ||
| 284 | server and tries to retrieve the daytime, printing the answer it got or an | ||
| 285 | error message. | ||
| 286 | </p> | ||
| 287 | |||
| 288 | <pre class=example> | ||
| 289 | host = "localhost" -- change here to the host you want to contact | ||
| 290 | port = port or 13 | ||
| 291 | -- convert host name to ip address | ||
| 292 | ip, err = socket.toip(host) | ||
| 293 | assert(ip, err) | ||
| 294 | -- create a new UDP object | ||
| 295 | udp = socket.udp() | ||
| 296 | -- contact daytime host | ||
| 297 | nsent, err = udp:sendto("anything", ip, port) | ||
| 298 | assert(not err, err) | ||
| 299 | -- retrieve the answer | ||
| 300 | dgram, err = udp:receive() | ||
| 301 | assert(dgram, err) | ||
| 302 | -- display to user | ||
| 303 | print(dgram) | ||
| 304 | </pre> | ||
| 305 | </blockquote> | ||
| 306 | |||
| 307 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 308 | |||
| 309 | <div class=footer> | ||
| 310 | <hr> | ||
| 311 | <center> | ||
| 312 | <p class=bar> | ||
| 313 | <a href="home.html">home</a> · | ||
| 314 | <a href="home.html#down">download</a> · | ||
| 315 | <a href="introduction.html">introduction</a> · | ||
| 316 | <a href="reference.html">reference</a> | ||
| 317 | </p> | ||
| 318 | <p> | ||
| 319 | <small> | ||
| 320 | Last modified by Diego Nehab on <br> | ||
| 321 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 322 | </small> | ||
| 323 | </p> | ||
| 324 | </center> | ||
| 325 | </div> | ||
| 326 | |||
| 327 | </body> | ||
| 328 | </html> | ||
diff --git a/doc/luasocket.png b/doc/luasocket.png new file mode 100644 index 0000000..d24a954 --- /dev/null +++ b/doc/luasocket.png | |||
| Binary files differ | |||
diff --git a/doc/reference.css b/doc/reference.css new file mode 100644 index 0000000..4f17046 --- /dev/null +++ b/doc/reference.css | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | body { | ||
| 2 | margin-left: 1em; | ||
| 3 | margin-right: 1em; | ||
| 4 | } | ||
| 5 | |||
| 6 | body > * { margin-left: 1em; } | ||
| 7 | |||
| 8 | div.header, div.footer { margin-left: 0em; } | ||
| 9 | hr, h1, h2, h3, h4 { margin-left: 0em; } | ||
| 10 | p.name { margin-left: 0em; } | ||
| 11 | |||
| 12 | h2:first-letter, h2:first-letter, h3:first-letter { color: #00007f; } | ||
| 13 | |||
| 14 | blockquote { margin-left: 3em; } | ||
| 15 | |||
| 16 | a[href] { color: #00007f; } | ||
| 17 | |||
| 18 | p.name { | ||
| 19 | font-size: large; | ||
| 20 | font-family: monospace; | ||
| 21 | padding-top: 1em; | ||
| 22 | } | ||
| 23 | |||
| 24 | pre.example { | ||
| 25 | background: #ccc; | ||
| 26 | font-size: small; | ||
| 27 | padding: 1em; | ||
| 28 | } | ||
| 29 | |||
| 30 | hr { | ||
| 31 | background: #00007f; | ||
| 32 | border: 0px; | ||
| 33 | height: 1px; | ||
| 34 | } | ||
| 35 | |||
| 36 | ul { list-style-type: disc; } | ||
| 37 | |||
| 38 | table.index { border: 1px #00007f; } | ||
| 39 | table.index td { text-align: left; vertical-align: top; } | ||
| 40 | table.index ul { padding-top: 0em; margin-top: 0em; } | ||
diff --git a/doc/reference.html b/doc/reference.html new file mode 100644 index 0000000..39f6437 --- /dev/null +++ b/doc/reference.html | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language </title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- reference +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2>Reference</h2> | ||
| 37 | |||
| 38 | <!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 39 | |||
| 40 | <table summary="TCP Index" class=index width=100%> | ||
| 41 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 42 | <tr> | ||
| 43 | <td><ul> | ||
| 44 | <li><a href="tcp.html">TCP (socket.tcp)</a> | ||
| 45 | <ul> | ||
| 46 | <li><a href="tcp.html#accept">accept</a> | ||
| 47 | <li><a href="tcp.html#bind">bind</a> | ||
| 48 | <li><a href="tcp.html#close">close</a> | ||
| 49 | <li><a href="tcp.html#connect">connect</a> | ||
| 50 | <li><a href="tcp.html#getpeername">getpeername</a> | ||
| 51 | </ul> | ||
| 52 | </ul></td> | ||
| 53 | <td valign=top><ul> | ||
| 54 | <li><a href="tcp.html#getsockname">getsockname</a> | ||
| 55 | <li><a href="tcp.html#receive">receive</a> | ||
| 56 | <li><a href="tcp.html#send">send</a> | ||
| 57 | <li><a href="tcp.html#setoption">setoption</a> | ||
| 58 | <li><a href="tcp.html#settimeout">settimeout</a> | ||
| 59 | </ul></td> | ||
| 60 | </tr> | ||
| 61 | </table> | ||
| 62 | |||
| 63 | <hr> | ||
| 64 | |||
| 65 | <!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 66 | |||
| 67 | <table summary="UDP Index" class=index width=100%> | ||
| 68 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 69 | <tr> | ||
| 70 | <td><ul> | ||
| 71 | <li><a href="udp.html">UDP (socket.udp)</a> | ||
| 72 | <ul> | ||
| 73 | <li><a href="udp.html#close">close</a> | ||
| 74 | <li><a href="udp.html#getpeername">getpeername</a> | ||
| 75 | <li><a href="udp.html#getsockname">getsockname</a> | ||
| 76 | <li><a href="udp.html#receive">receive</a> | ||
| 77 | <li><a href="udp.html#receivefrom">receivefrom</a> | ||
| 78 | </ul> | ||
| 79 | </ul></td> | ||
| 80 | <td><ul> | ||
| 81 | <li><a href="udp.html#send">send</a> | ||
| 82 | <li><a href="udp.html#sendto">sendto</a> | ||
| 83 | <li><a href="udp.html#setpeername">setpeername</a> | ||
| 84 | <li><a href="udp.html#setsockname">setsockname</a> | ||
| 85 | <li><a href="udp.html#setoption">setoption</a> | ||
| 86 | <li><a href="udp.html#settimeout">settimeout</a> | ||
| 87 | </ul></td> | ||
| 88 | </tr> | ||
| 89 | </table> | ||
| 90 | |||
| 91 | <hr> | ||
| 92 | |||
| 93 | <!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 94 | |||
| 95 | <table summary="HTTP and FTP Index" class=index width=100% rules=cols> | ||
| 96 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 97 | <tr> | ||
| 98 | <td valign=top><ul> | ||
| 99 | <li><a href="http.html">HTTP (socket.http)</a> | ||
| 100 | <ul> | ||
| 101 | <li><a href="http.html#get">get</a> | ||
| 102 | <li><a href="http.html#post">post</a> | ||
| 103 | <li><a href="http.html#request">request</a> | ||
| 104 | <li><a href="http.html#request_cb">request_cb</a> | ||
| 105 | </ul> | ||
| 106 | </ul></td> | ||
| 107 | <td valign=top><ul> | ||
| 108 | <li><a href="ftp.html">FTP (socket.ftp)</a> | ||
| 109 | <ul> | ||
| 110 | <li><a href="ftp.html#get">get</a> | ||
| 111 | <li><a href="ftp.html#get_cb">get_cb</a> | ||
| 112 | <li><a href="ftp.html#put">put</a> | ||
| 113 | <li><a href="ftp.html#put_cb">put_cb</a> | ||
| 114 | </ul> | ||
| 115 | </ul></td> | ||
| 116 | </tr> | ||
| 117 | </table> | ||
| 118 | |||
| 119 | <hr> | ||
| 120 | |||
| 121 | <!-- http & ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 122 | |||
| 123 | <table summary="Streaming Index" class=index width=100%> | ||
| 124 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 125 | <tr><td valign=top><ul> | ||
| 126 | <li><a href="stream.html">Streaming with Callbacks</a> | ||
| 127 | <ul> | ||
| 128 | <li><a href="stream.html#receive_cb">receive_cb</a> | ||
| 129 | <li><a href="stream.html#send_cb">send_cb</a> | ||
| 130 | </ul> | ||
| 131 | </ul></td></tr> | ||
| 132 | </table> | ||
| 133 | |||
| 134 | <hr> | ||
| 135 | |||
| 136 | <!-- smtp & dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 137 | |||
| 138 | <table summary="SMTP and DNS Index" class=index width=100% rules=cols> | ||
| 139 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 140 | <tr> | ||
| 141 | <td><ul> | ||
| 142 | <li><a href="smtp.html">SMTP (socket.smtp)</a> | ||
| 143 | <ul> | ||
| 144 | <li> <a href="mod.html#mail">mail</a> | ||
| 145 | </ul> | ||
| 146 | </ul></td> | ||
| 147 | <td><ul> | ||
| 148 | <li><a href="dns.html">DNS services (socket.dns)</a> | ||
| 149 | <ul> | ||
| 150 | <li><a href="dns.html#toip">toip</a> | ||
| 151 | <li><a href="dns.html#tohostname">tohostname</a> | ||
| 152 | </ul> | ||
| 153 | </ul></td> | ||
| 154 | </tr> | ||
| 155 | </table> | ||
| 156 | |||
| 157 | <hr> | ||
| 158 | |||
| 159 | <!-- url & code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 160 | |||
| 161 | <table summary="URL and Code Index" class=index width=100% rules=cols> | ||
| 162 | <colgroup> <col width="50%"> <col width="50%"> </colgroup> | ||
| 163 | <tr> | ||
| 164 | <td valign=top><ul> | ||
| 165 | <li><a href="url.html">URL (socket.url) </a> | ||
| 166 | <ul> | ||
| 167 | <li> <a href="url.html#absolute">absolute</a> | ||
| 168 | <li> <a href="url.html#build">build</a> | ||
| 169 | <li> <a href="url.html#build_path">build_path</a> | ||
| 170 | <li> <a href="url.html#parse">parse</a> | ||
| 171 | <li> <a href="url.html#parse_path">parse_path</a> | ||
| 172 | </ul> | ||
| 173 | </ul></td> | ||
| 174 | <td valign=top><ul> | ||
| 175 | <li> <a href="code.html">Code (socket.code) </a> | ||
| 176 | <ul> | ||
| 177 | <li> <a href="code.html#base64">base64</a> | ||
| 178 | <li> <a href="code.html#unbase64">unbase64</a> | ||
| 179 | <li> <a href="code.html#escape">escape</a> | ||
| 180 | <li> <a href="code.html#unescape">unescape</a> | ||
| 181 | <li> <a href="code.html#hexa">hexa</a> | ||
| 182 | <li> <a href="code.html#unhexa">unhexa</a> | ||
| 183 | </ul> | ||
| 184 | </ul></td> | ||
| 185 | </tr> | ||
| 186 | </table> | ||
| 187 | |||
| 188 | <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 189 | |||
| 190 | <div class=footer> | ||
| 191 | <hr> | ||
| 192 | <center> | ||
| 193 | <p class=bar> | ||
| 194 | <a href="home.html">home</a> · | ||
| 195 | <a href="home.html#down">download</a> · | ||
| 196 | <a href="introduction.html">introduction</a> · | ||
| 197 | <a href="reference.html">reference</a> | ||
| 198 | </p> | ||
| 199 | <p> | ||
| 200 | <small> | ||
| 201 | Last modified by Diego Nehab on <br> | ||
| 202 | Thu Sep 27 16:18:27 EST 2001 | ||
| 203 | </small> | ||
| 204 | </p> | ||
| 205 | </center> | ||
| 206 | </div> | ||
| 207 | |||
| 208 | </body> | ||
| 209 | </html> | ||
diff --git a/doc/smtp.html b/doc/smtp.html new file mode 100644 index 0000000..3a30a07 --- /dev/null +++ b/doc/smtp.html | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=smtp>SMTP</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | The module <tt>smtp.lua</tt> provides functionality to send e-mail | ||
| 40 | messages. The implementation conforms to the Simple Mail Transfer Protocol, | ||
| 41 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2821.txt">RFC 2821</a>. | ||
| 42 | The other RFC of interest in this implementation is | ||
| 43 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a>, | ||
| 44 | which governs the Internet Message Format. | ||
| 45 | |||
| 46 | </p> | ||
| 47 | |||
| 48 | <p> | ||
| 49 | MIME headers are represented as a Lua table in the form: | ||
| 50 | </p> | ||
| 51 | |||
| 52 | <blockquote> | ||
| 53 | <table summary="MIME headers in Lua table"> | ||
| 54 | <tr><td><tt> | ||
| 55 | headers = {<br> | ||
| 56 | field-1-name = <i>field-1-value</i>,<br> | ||
| 57 | field-2-name = <i>field-2-value</i>,<br> | ||
| 58 | field-3-name = <i>field-3-value</i>, | ||
| 59 | </tt></td></tr> | ||
| 60 | <tr><td align=center><tt> | ||
| 61 | ... | ||
| 62 | </tt></td></tr> | ||
| 63 | <tr><td><tt> | ||
| 64 | field-n-name = <i>field-n-value</i><br> | ||
| 65 | } | ||
| 66 | </tt></td></tr> | ||
| 67 | </table> | ||
| 68 | </blockquote> | ||
| 69 | |||
| 70 | <p> | ||
| 71 | Field names are case insensitive (as specified by the standard) and all | ||
| 72 | functions work with lowercase field names. | ||
| 73 | Field values are left unmodified. | ||
| 74 | </p> | ||
| 75 | |||
| 76 | <p class=note> | ||
| 77 | Note: MIME headers are independent of order. Therefore, there is no problem | ||
| 78 | in representing them in a Lua table. | ||
| 79 | </p> | ||
| 80 | |||
| 81 | <!-- mail +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 82 | |||
| 83 | <p class=name id=mail> | ||
| 84 | socket.smtp.<b>mail{</b><br> | ||
| 85 | from = <i>string</i>,<br> | ||
| 86 | rcpt = <i>string</i> or <i>string-table</i>,<br> | ||
| 87 | body = <i>string</i>,<br> | ||
| 88 | headers = <i>headers-table</i>,<br> | ||
| 89 | server = <i>string</i><br> | ||
| 90 | <b>}</b> | ||
| 91 | </p> | ||
| 92 | |||
| 93 | <p class=description> | ||
| 94 | Sends a message to a recipient list. | ||
| 95 | </p> | ||
| 96 | |||
| 97 | <p class=parameters> | ||
| 98 | <tt>Rcpt</tt> is a Lua table with one entry for each recipient, or a string | ||
| 99 | in case there is just one recipient. | ||
| 100 | The sender is given by the e-mail address <tt>from</tt>. | ||
| 101 | The message is composed by the optional MIME Headers <tt>headers</tt> | ||
| 102 | and text <tt>body</tt>. The message is sent using the server | ||
| 103 | <tt>server</tt>. | ||
| 104 | </p> | ||
| 105 | |||
| 106 | <p class=return> | ||
| 107 | If successful, the function returns 1. Otherwise, the function returns | ||
| 108 | <tt>nil</tt> followed by an error message. | ||
| 109 | </p> | ||
| 110 | |||
| 111 | <p class=note> | ||
| 112 | Big note: There is a good deal of misconception with the use of the | ||
| 113 | destination address field headers, i.e., the '<tt>To</tt>', '<tt>Cc</tt>', | ||
| 114 | and, more importantly, the '<tt>Bcc</tt>' headers. Do <em>not</em> add a | ||
| 115 | '<tt>Bcc</tt>' header to your messages because it will probably do the | ||
| 116 | exact opposite of what you expect. | ||
| 117 | </p> | ||
| 118 | |||
| 119 | <p class=note> | ||
| 120 | Only recipients specified in the recipient list will receive a copy of the | ||
| 121 | message. Each recipient of an SMTP mail message receives a copy of the | ||
| 122 | message body along with the headers, and nothing more. The headers are | ||
| 123 | considered as part of the message. The list of recipients is <em>not</em> | ||
| 124 | part of the message. | ||
| 125 | </p> | ||
| 126 | |||
| 127 | <p class=note> | ||
| 128 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a> | ||
| 129 | has two <em>important and short</em> sections, "3.6.3. Destination address | ||
| 130 | fields" and "5. Security considerations", explaining the proper | ||
| 131 | use of these headers. Here is a summary of what it says: | ||
| 132 | </p> | ||
| 133 | |||
| 134 | <ul> | ||
| 135 | <li> <tt>To</tt>: contains the address(es) of the primary recipient(s) | ||
| 136 | of the message; | ||
| 137 | <li> <tt>Cc</tt>: (where the "Cc" means "Carbon Copy" in the sense of | ||
| 138 | making a copy on a typewriter using carbon paper) contains the | ||
| 139 | addresses of others who are to receive the message, though the | ||
| 140 | content of the message may not be directed at them; | ||
| 141 | <li> <tt>Bcc</tt>: (where the "Bcc" means "Blind Carbon | ||
| 142 | Copy") contains addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message. | ||
| 143 | </ul> | ||
| 144 | |||
| 145 | <p class=note> | ||
| 146 | The LuaSocket <tt>mail</tt> function does not interpret the headers you | ||
| 147 | pass to, but it gives you full control over what is sent and to whom | ||
| 148 | it is sent: | ||
| 149 | </p> | ||
| 150 | <ul> | ||
| 151 | <li> If someone is to receive the message, the e-mail address <em>has</em> | ||
| 152 | to be in the recipient list. This is the only parameter that controls who | ||
| 153 | gets a copy of the message; | ||
| 154 | <li> If there are multiple recipients, none of them will automatically | ||
| 155 | know that someone else got that message. That is, the default behavior is | ||
| 156 | similar to the <tt>Bcc</tt> field of popular e-mail clients; | ||
| 157 | <li> It is up to you to add the <tt>To</tt> header with the list of primary | ||
| 158 | recipients so that other recipients can see it; | ||
| 159 | <li> It is also up to you to add the <tt>Cc</tt> header with the | ||
| 160 | list of additional recipients so that everyone else sees it; | ||
| 161 | <li> Adding a header <tt>Bcc</tt> is nonsense, unless it is | ||
| 162 | empty. Otherwise, everyone receiving the message will see it and that is | ||
| 163 | exactly what you <em>don't</em> want to happen! | ||
| 164 | </ul> | ||
| 165 | |||
| 166 | <p class=note> | ||
| 167 | I hope this clarifies the issue. Otherwise, please refer to | ||
| 168 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2821.txt">RFC 2821</a> | ||
| 169 | and | ||
| 170 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a>. | ||
| 171 | </p> | ||
| 172 | |||
| 173 | <pre class=example> | ||
| 174 | -- Connects to server "localhost" and sends a message to users | ||
| 175 | -- "fulano@tecgraf.puc-rio.br", "beltrano@tecgraf.puc-rio.br", | ||
| 176 | -- and "sicrano@tecgraf.puc-rio.br". | ||
| 177 | -- Note that "fulano" is the primary recipient, "beltrano" receives a | ||
| 178 | -- carbon copy and neither of them knows that "sicrano" received a blind | ||
| 179 | -- carbon copy of the message. | ||
| 180 | headers = { | ||
| 181 | to = "fulano@tecgraf.puc-rio.br", | ||
| 182 | cc = "beltrano@tecgraf.puc-rio.br", | ||
| 183 | subject = "LuaSocket test message" | ||
| 184 | } | ||
| 185 | |||
| 186 | from = "luasocket@tecgraf.puc-rio.br" | ||
| 187 | |||
| 188 | rcpt = { | ||
| 189 | "fulano@tecgraf.puc-rio.br", | ||
| 190 | "beltrano@tecgraf.puc-rio.br", | ||
| 191 | "sicrano@tecgraf.puc-rio.br" | ||
| 192 | } | ||
| 193 | |||
| 194 | body = "This is a test message. Please ignore." | ||
| 195 | |||
| 196 | server = "localhost" | ||
| 197 | |||
| 198 | r, e = socket.smtp.mail{ | ||
| 199 | from = from, | ||
| 200 | rcpt = rcpt, | ||
| 201 | headers = headers, | ||
| 202 | body = body, | ||
| 203 | server = server | ||
| 204 | } | ||
| 205 | </pre> | ||
| 206 | |||
| 207 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 208 | |||
| 209 | <div class=footer> | ||
| 210 | <hr> | ||
| 211 | <center> | ||
| 212 | <p class=bar> | ||
| 213 | <a href="home.html">home</a> · | ||
| 214 | <a href="home.html#down">download</a> · | ||
| 215 | <a href="introduction.html">introduction</a> · | ||
| 216 | <a href="reference.html">reference</a> | ||
| 217 | </p> | ||
| 218 | <p> | ||
| 219 | <small> | ||
| 220 | Last modified by Diego Nehab on <br> | ||
| 221 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 222 | </small> | ||
| 223 | </p> | ||
| 224 | </center> | ||
| 225 | </div> | ||
| 226 | |||
| 227 | </body> | ||
| 228 | </html> | ||
diff --git a/doc/stream.html b/doc/stream.html new file mode 100644 index 0000000..296ca2e --- /dev/null +++ b/doc/stream.html | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- stream ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=stream>Streaming with Callbacks</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | HTTP and FTP transfers sometimes involve large amounts of information. | ||
| 40 | Sometimes an application needs to generate outgoing data in real time, | ||
| 41 | or needs to process incoming information as it is being received. To | ||
| 42 | address these problems, LuaSocket allows HTTP message bodies and FTP | ||
| 43 | file contents to be received or sent through the callback mechanism | ||
| 44 | outlined below. | ||
| 45 | </p> | ||
| 46 | |||
| 47 | <p> | ||
| 48 | Instead of returning the entire contents of a FTP file or HTTP message | ||
| 49 | body as strings to the Lua application, the library allows the user to | ||
| 50 | provide a <em>receive callback</em> that will be called with successive | ||
| 51 | chunks of data, as the data becomes available. Conversely, the <em>send | ||
| 52 | callbacks</em> should be used when data needed by LuaSocket | ||
| 53 | is generated incrementally by the application. | ||
| 54 | </p> | ||
| 55 | |||
| 56 | <!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 57 | |||
| 58 | <p class=name id=receive_cb> | ||
| 59 | <b>receive_cb(</b>chunk, err<b>)</b> | ||
| 60 | </p> | ||
| 61 | |||
| 62 | <p class=description> | ||
| 63 | The callback provided by the user will be repeatedly called by the | ||
| 64 | library whenever new data is available. Each time it is called, the | ||
| 65 | callback receives successive chunks of downloaded data. | ||
| 66 | </p> | ||
| 67 | |||
| 68 | <p class=parameters> | ||
| 69 | <tt>Chunk</tt> contains the current chunk of data. | ||
| 70 | When the transmission is over, the function is called with an | ||
| 71 | empty string (i.e. <tt>""</tt>) as the <tt>chunk</tt>. If an error occurs, the | ||
| 72 | function receives <tt>nil</tt> as <tt>chunk</tt> and an error message as | ||
| 73 | <tt>err</tt>. | ||
| 74 | </p> | ||
| 75 | |||
| 76 | <p class=return> | ||
| 77 | The callback can abort transmission by returning | ||
| 78 | <tt>nil</tt> as its first return value. In that case, it can also return | ||
| 79 | an error message. Any non-<tt>nil</tt> return value proceeds with the | ||
| 80 | transmission. | ||
| 81 | </p> | ||
| 82 | |||
| 83 | <pre class=example> | ||
| 84 | -- The implementation of socket.callback.receive_concat | ||
| 85 | function Public.receive_concat(concat) | ||
| 86 | concat = concat or socket.concat.create() | ||
| 87 | local callback = function(chunk, err) | ||
| 88 | -- if not finished, add chunk | ||
| 89 | if chunk and chunk ~= "" then | ||
| 90 | concat:addstring(chunk) | ||
| 91 | return 1 | ||
| 92 | end | ||
| 93 | end | ||
| 94 | return callback, concat | ||
| 95 | end | ||
| 96 | </pre> | ||
| 97 | |||
| 98 | <!-- send_cb ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 99 | |||
| 100 | <p class=name> | ||
| 101 | <b>send_cb()</b> | ||
| 102 | </p> | ||
| 103 | |||
| 104 | <p class=description> | ||
| 105 | The callback provided by the user will be repeatedly called whenever the | ||
| 106 | library needs more data to be sent. | ||
| 107 | </p> | ||
| 108 | |||
| 109 | <p class=return> | ||
| 110 | Each time the callback is called, it | ||
| 111 | should return the next part of the information the library is expecting, | ||
| 112 | followed by the total number of bytes to be sent. | ||
| 113 | The callback can abort | ||
| 114 | the process at any time by returning <tt>nil</tt> followed by an | ||
| 115 | optional error message. | ||
| 116 | </p> | ||
| 117 | |||
| 118 | |||
| 119 | <p class=note> | ||
| 120 | Note: The need for the second return value comes from the fact that, with | ||
| 121 | the HTTP protocol for instance, the library needs to know in advance the | ||
| 122 | total number of bytes that will be sent. | ||
| 123 | </p> | ||
| 124 | |||
| 125 | <pre class=example> | ||
| 126 | -- The implementation of socket.callback.send_file | ||
| 127 | function Public.send_file(file) | ||
| 128 | local callback | ||
| 129 | -- if successfull, return the callback that reads from the file | ||
| 130 | if file then | ||
| 131 | -- get total size | ||
| 132 | local size = file:seek("end") | ||
| 133 | -- go back to start of file | ||
| 134 | file:seek("set") | ||
| 135 | callback = function() | ||
| 136 | -- send next block of data | ||
| 137 | local chunk = file:read(Public.BLOCKSIZE) | ||
| 138 | if not chunk then file:close() end | ||
| 139 | return chunk, size | ||
| 140 | end | ||
| 141 | -- else, return a callback that just aborts the transfer | ||
| 142 | else | ||
| 143 | callback = function() | ||
| 144 | -- just abort | ||
| 145 | return nil, "unable to open file" | ||
| 146 | end | ||
| 147 | end | ||
| 148 | return callback, file | ||
| 149 | end | ||
| 150 | </pre> | ||
| 151 | |||
| 152 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 153 | |||
| 154 | <div class=footer> | ||
| 155 | <hr> | ||
| 156 | <center> | ||
| 157 | <p class=bar> | ||
| 158 | <a href="home.html">home</a> · | ||
| 159 | <a href="home.html#down">download</a> · | ||
| 160 | <a href="introduction.html">introduction</a> · | ||
| 161 | <a href="reference.html">reference</a> | ||
| 162 | </p> | ||
| 163 | <p> | ||
| 164 | <small> | ||
| 165 | Last modified by Diego Nehab on <br> | ||
| 166 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 167 | </small> | ||
| 168 | </p> | ||
| 169 | </center> | ||
| 170 | </div> | ||
| 171 | |||
| 172 | </body> | ||
| 173 | </html> | ||
diff --git a/doc/tcp.html b/doc/tcp.html new file mode 100644 index 0000000..ecbedaa --- /dev/null +++ b/doc/tcp.html | |||
| @@ -0,0 +1,415 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=tcp>TCP</h2> | ||
| 37 | |||
| 38 | <!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 39 | |||
| 40 | <p class=name id=socket.tcp> | ||
| 41 | socket.<b>tcp()</b> | ||
| 42 | </p> | ||
| 43 | |||
| 44 | <p class=description> | ||
| 45 | Creates and returns a TCP master object. A master object can | ||
| 46 | be transformed into a server object with the method | ||
| 47 | <a href=#bind><tt>bind</tt></a> or into a client object with the method | ||
| 48 | <a href=#connect><tt>connect</tt></a>. The only other method | ||
| 49 | supported by a master object is the <a href=#close><tt>close</tt></a> | ||
| 50 | method.</p> | ||
| 51 | |||
| 52 | <p class=return> | ||
| 53 | In case of success, a new master object is returned. In case of error, | ||
| 54 | <tt>nil</tt> is returned, followed by an error message. | ||
| 55 | </p> | ||
| 56 | |||
| 57 | <!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 58 | |||
| 59 | <p class=name id=accept> | ||
| 60 | server:<b>accept()</b> | ||
| 61 | </p> | ||
| 62 | |||
| 63 | <p class=description> | ||
| 64 | Waits for a remote connection on the server | ||
| 65 | object and returns a client object representing that connection. | ||
| 66 | </p> | ||
| 67 | |||
| 68 | <p class=return> | ||
| 69 | If a connection is successfully initiated, a client object is returned. | ||
| 70 | If a timeout condition is met, the method returns <tt>nil</tt> followed | ||
| 71 | by the error string '<tt>timeout</tt>'. | ||
| 72 | </p> | ||
| 73 | |||
| 74 | <p class=note> | ||
| 75 | Note: calling <a href=misc.html#socket.select><tt>socket.select</tt></a> | ||
| 76 | with a server object in | ||
| 77 | the <tt>receive</tt> parameter before a call to <tt>accept</tt> does | ||
| 78 | <em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a | ||
| 79 | href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt> | ||
| 80 | might block until <em>another</em> client shows up. | ||
| 81 | </p> | ||
| 82 | |||
| 83 | <!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 84 | |||
| 85 | <p class=name id=bind> | ||
| 86 | master:<b>bind(</b>address, port [, backlog]<b>)</b> | ||
| 87 | </p> | ||
| 88 | |||
| 89 | <p class=description> | ||
| 90 | Binds a master object to <tt>address</tt> and <tt>port</tt> on the | ||
| 91 | local host, transforming it into a server object. Server | ||
| 92 | objects support the | ||
| 93 | <a href=#accept><tt>accept</tt></a>, | ||
| 94 | <a href=#getsockname><tt>getsockname</tt></a>, | ||
| 95 | <a href=#setoption><tt>setoption</tt></a>, | ||
| 96 | <a href=#settimeout><tt>settimeout</tt></a>, | ||
| 97 | and <a href=#close><tt>close</tt></a> methods. | ||
| 98 | </p> | ||
| 99 | |||
| 100 | <p class=parameters> | ||
| 101 | <tt>Address</tt> can be an IP address or a host name. | ||
| 102 | <tt>Port</tt> must be an integer number in the range [0..64K]. | ||
| 103 | If <tt>address</tt> | ||
| 104 | is '<tt>*</tt>', the system binds to all local interfaces | ||
| 105 | using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically | ||
| 106 | chooses an ephemeral port. The optional parameter <tt>backlog</tt>, which | ||
| 107 | defaults to 1, specifies the number of client connections that can | ||
| 108 | be queued waiting for service. If the queue is full and another client | ||
| 109 | attempts connection, the connection is refused. | ||
| 110 | </p> | ||
| 111 | |||
| 112 | <p class=return> | ||
| 113 | In case of success, the method returns 1. In case of error, the | ||
| 114 | method returns <tt>nil</tt> followed by an error message. | ||
| 115 | </p> | ||
| 116 | |||
| 117 | <p class=note> | ||
| 118 | Note: The function <tt>socket.bind</tt> is available and is a short | ||
| 119 | for <a href=#socket.tcp><tt>socket.tcp</tt></a> followed by the <tt>bind</tt> method. | ||
| 120 | </p> | ||
| 121 | |||
| 122 | <!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 123 | |||
| 124 | <p class=name id=close> | ||
| 125 | master:<b>close()</b><br> | ||
| 126 | client:<b>close()</b><br> | ||
| 127 | server:<b>close()</b> | ||
| 128 | </p> | ||
| 129 | |||
| 130 | <p class=description> | ||
| 131 | Closes a TCP object. The internal socket used by the object is closed | ||
| 132 | and the local address to which the object was | ||
| 133 | bound is made available to other applications. No further operations | ||
| 134 | (except for further calls to the <tt>close</tt> method) are allowed on | ||
| 135 | a closed socket. | ||
| 136 | </p> | ||
| 137 | |||
| 138 | <p class=note> | ||
| 139 | Note: It is important to close all used sockets once they are not | ||
| 140 | needed, since, in many systems, each socket uses a file descriptor, | ||
| 141 | which are limited system resources. Garbage-collected objects are | ||
| 142 | automatically closed before destruction, though. | ||
| 143 | </p> | ||
| 144 | |||
| 145 | <!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 146 | |||
| 147 | <p class=name id=connect> | ||
| 148 | master:<b>connect(</b>address, port<b>)</b> | ||
| 149 | </p> | ||
| 150 | |||
| 151 | <p class=description> | ||
| 152 | Attempts to connect a master object to a remote host, transforming it into a | ||
| 153 | client object. Client objects support methods | ||
| 154 | <a href=#send><tt>send</tt></a>, | ||
| 155 | <a href=#receive><tt>receive</tt></a>, | ||
| 156 | <a href=#getsockname><tt>getsockname</tt></a>, | ||
| 157 | <a href=#getpeername><tt>getpeername</tt></a>, | ||
| 158 | <a href=#settimeout><tt>settimeout</tt></a>, | ||
| 159 | and <a href=#close><tt>close</tt></a>. | ||
| 160 | </p> | ||
| 161 | |||
| 162 | <p class=parameters> | ||
| 163 | <tt>Address</tt> can be an IP address or a host name. | ||
| 164 | <tt>Port</tt> must be an integer number in the range [1..64K]. | ||
| 165 | </p> | ||
| 166 | |||
| 167 | <p class=return> | ||
| 168 | In case of error, the method returns <tt>nil</tt> followed by a string | ||
| 169 | describing the error. In case of success, the method returns 1. | ||
| 170 | </p> | ||
| 171 | |||
| 172 | <p class=note> | ||
| 173 | Note: The function <tt>socket.connect</tt> is available and is a short | ||
| 174 | for <a href=#socket.tcp><tt>socket.tcp</tt></a> followed by the <tt>connect</tt> method. | ||
| 175 | </p> | ||
| 176 | |||
| 177 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 178 | |||
| 179 | <p class=name id=getpeername> | ||
| 180 | client:<b>getpeername()</b> | ||
| 181 | </p> | ||
| 182 | |||
| 183 | <p class=description> | ||
| 184 | Returns information about the remote side of a connected client object. | ||
| 185 | </p> | ||
| 186 | |||
| 187 | <p class=return> | ||
| 188 | Returns a string with the IP address of the peer, followed by the | ||
| 189 | port number that peer is using for the connection. | ||
| 190 | In case of error, the method returns <tt>nil</tt>. | ||
| 191 | </p> | ||
| 192 | |||
| 193 | <p class=note> | ||
| 194 | Note: It makes no sense to call this method on server objects. | ||
| 195 | </p> | ||
| 196 | |||
| 197 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 198 | |||
| 199 | <p class=name id=getsockname> | ||
| 200 | client:<b>getsockname()</b><br> | ||
| 201 | server:<b>getsockname()</b> | ||
| 202 | </p> | ||
| 203 | |||
| 204 | <p class=description> | ||
| 205 | Returns the local address information associated to the object. | ||
| 206 | </p> | ||
| 207 | |||
| 208 | <p class=return> | ||
| 209 | The method returns a string with local IP address and a number with | ||
| 210 | the port. In case of error, the method returns <tt>nil</tt>. | ||
| 211 | </p> | ||
| 212 | |||
| 213 | <p class=note> | ||
| 214 | Note: Naturally, for a server object, the address and port returned are | ||
| 215 | those passed to the <a href=#bind>bind</a> method. If the port value | ||
| 216 | passed to bind was 0, the OS assigned ephemeral port is returned. For | ||
| 217 | client objects, both the address and port are ephemeral and these are the | ||
| 218 | values returned. | ||
| 219 | </p> | ||
| 220 | |||
| 221 | <!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 222 | |||
| 223 | <p class=name id=receive> | ||
| 224 | client:<b>receive(</b>[pattern<sub>1</sub>, pattern<sub>2</sub>, | ||
| 225 | ... pattern<sub>N</sub>]<b>)</b> | ||
| 226 | </p> | ||
| 227 | |||
| 228 | <p class=description> | ||
| 229 | Reads data from a client object, according to the specified <em>read | ||
| 230 | patterns</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. | ||
| 231 | </p> | ||
| 232 | |||
| 233 | <p class=parameters> | ||
| 234 | The parameters <tt>pattern</tt><sub>1</sub>, <tt>pattern</tt><sub>2</sub>, ... | ||
| 235 | <tt>pattern</tt><sub>N</sub> can be any of the following: | ||
| 236 | </p> | ||
| 237 | |||
| 238 | <ul> | ||
| 239 | <li> '<tt>*a</tt>': reads from the socket until the connection is | ||
| 240 | closed. No end-of-line translation is performed; | ||
| 241 | <li> '<tt>*l</tt>': reads a line of text from the socket. The line is | ||
| 242 | terminated by a LF character (ASCII 10), optionally preceded by a | ||
| 243 | CR character (ASCII 13). The CR and LF characters are not included in | ||
| 244 | the returned line. This is the default pattern; | ||
| 245 | <li> <tt>number</tt>: causes the method to read <tt>number</tt> raw | ||
| 246 | bytes from the socket. | ||
| 247 | </ul> | ||
| 248 | |||
| 249 | <p class=return> | ||
| 250 | The method returns one value for each pattern, followed by a single | ||
| 251 | error code that can be <tt>nil</tt> in case of success, the string | ||
| 252 | '<tt>closed</tt>' in case the connection was closed before the | ||
| 253 | transmission was completed or the string '<tt>timeout</tt>' in case | ||
| 254 | there was a timeout during the operation. | ||
| 255 | </p> | ||
| 256 | |||
| 257 | <p class=note> | ||
| 258 | Note: In case of error, the method always return everything it managed | ||
| 259 | to download before the error condition was met. | ||
| 260 | </p> | ||
| 261 | |||
| 262 | <!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 263 | |||
| 264 | <p class=name id=send> | ||
| 265 | client:<b>send(</b>string<sub>1</sub> [, | ||
| 266 | string<sub>2</sub>, ... string<sub>N</sub>]<b>)</b> | ||
| 267 | </p> | ||
| 268 | |||
| 269 | <p class=description> | ||
| 270 | Sends data through client object. | ||
| 271 | </p> | ||
| 272 | |||
| 273 | <p class=parameters> | ||
| 274 | All parameters should be strings. For small strings, it is always better to | ||
| 275 | concatenate them in Lua (with the '<tt>..</tt>' operator) and pass the | ||
| 276 | result to LuaSocket instead of passing several independent strings. | ||
| 277 | </p> | ||
| 278 | |||
| 279 | <p class=return> | ||
| 280 | The method returns the number of bytes accepted by the transport layer, | ||
| 281 | followed by an error code. The error code is <tt>nil</tt> if the operation | ||
| 282 | completed with no errors, the string '<tt>closed</tt>' in case | ||
| 283 | the connection was closed before the transmission was completed or the | ||
| 284 | string '<tt>timeout</tt>' in case there was a timeout during the | ||
| 285 | operation. | ||
| 286 | </p> | ||
| 287 | |||
| 288 | <p class=note> | ||
| 289 | Note: The return values for the <tt>send</tt> method have been changed in | ||
| 290 | LuaSocket 2.0! In previous versions, the method returned only the | ||
| 291 | error message. Since returning <tt>nil</tt> in case of success goes | ||
| 292 | against all other LuaSocket methods and functions, the | ||
| 293 | <tt>send</tt> method been changed for the sake of uniformity. | ||
| 294 | </p> | ||
| 295 | |||
| 296 | <!-- setoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 297 | |||
| 298 | <p class=name id=setoption> | ||
| 299 | client:<b>setoption(</b>option [, value]<b>)</b><br> | ||
| 300 | server:<b>setoption(</b>option [, value]<b>)</b> | ||
| 301 | </p> | ||
| 302 | |||
| 303 | <p class=description> | ||
| 304 | Sets options for the TCP object. Options are only needed by low-level or | ||
| 305 | time-critical applications. You should only modify a an option if you | ||
| 306 | are sure you need it. | ||
| 307 | </p> | ||
| 308 | |||
| 309 | <p class=parameters> | ||
| 310 | <tt>Option</tt> is a string with the option name, and <tt>value</tt> | ||
| 311 | depends on the option being set: | ||
| 312 | |||
| 313 | <ul> | ||
| 314 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> disables the | ||
| 315 | Nagle's algorithm for the connection; | ||
| 316 | <li> '<tt>linger</tt>': Controls the action taken when unsent data are | ||
| 317 | queued on socket and a close is performed. The value is a table with a | ||
| 318 | boolean entry '<tt>on</tt>' and a numeric entry for the time interval | ||
| 319 | '<tt>timeout</tt>' in seconds. | ||
| 320 | If the '<tt>on</tt>' field is set to <tt>true</tt>, | ||
| 321 | the system will block the process on the close attempt until it is able to | ||
| 322 | transmit the data or until '<tt>timeout</tt>' has passed. If '<tt>on</tt>' | ||
| 323 | is <tt>false</tt> and a close is issued, the system will process the close | ||
| 324 | in a manner that allows the process to continue as quickly as possible. I | ||
| 325 | do not advise you to set this to anything other than zero. | ||
| 326 | <li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables | ||
| 327 | the periodic transmission of messages on a connected socket. Should the | ||
| 328 | connected party fail to respond to these messages, the connection is | ||
| 329 | considered broken and processes using the socket are notified. | ||
| 330 | </ul> | ||
| 331 | |||
| 332 | <p class=return> | ||
| 333 | The method returns 1 in case of success, or <tt>nil</tt> otherwise. | ||
| 334 | </p> | ||
| 335 | |||
| 336 | <p class=note> | ||
| 337 | Note: The descriptions above come from the man pages. | ||
| 338 | </p> | ||
| 339 | |||
| 340 | <!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 341 | |||
| 342 | <p class=name id=settimeout> | ||
| 343 | client:<b>settimeout(</b>value [, mode]<b>)</b><br> | ||
| 344 | server:<b>settimeout(</b>value [, mode]<b>)</b> | ||
| 345 | </p> | ||
| 346 | |||
| 347 | <p class=description> | ||
| 348 | Changes the timeout values for the object. By default, | ||
| 349 | all I/O operations are blocking. That is, any call to the methods | ||
| 350 | <a href=#send><tt>send</tt></a>, | ||
| 351 | <a href=#receive><tt>receive</tt></a>, and | ||
| 352 | <a href=#accept><tt>accept</tt></a> | ||
| 353 | will block indefinitely, until the operation completes. The | ||
| 354 | <tt>settimeout</tt> method defines a limit on the amount of time the | ||
| 355 | I/O methods can block. When a timeout is set and the specified amount of | ||
| 356 | time has elapsed, the affected methods give up and fail with an error code. | ||
| 357 | </p> | ||
| 358 | |||
| 359 | <p class=parameters> | ||
| 360 | The amount of time to wait is specified as the | ||
| 361 | <tt>value</tt> parameter, in seconds. There are two timeout modes and | ||
| 362 | both can be used together for fine tuning: | ||
| 363 | </p> | ||
| 364 | |||
| 365 | <ul> | ||
| 366 | <li> '<tt>b</tt>': <em>block</em> timeout. Specifies the upper limit on | ||
| 367 | the amount of time LuaSocket can be blocked by the operating system | ||
| 368 | while waiting for completion of any single I/O operation. This is the | ||
| 369 | default mode;</li> | ||
| 370 | |||
| 371 | <li> '<tt>t</tt>': <em>total</em> timeout. Specifies the upper limit on | ||
| 372 | the amount of time LuaSocket can block a Lua script before returning from | ||
| 373 | a call.</li> | ||
| 374 | </ul> | ||
| 375 | |||
| 376 | <p class=parameters> | ||
| 377 | The <tt>nil</tt> timeout <tt>value</tt> allows operations to block | ||
| 378 | indefinitely. Negative timeout values have the same effect. | ||
| 379 | </p> | ||
| 380 | |||
| 381 | <p class=note> | ||
| 382 | Note: although timeout values have millisecond precision in LuaSocket, | ||
| 383 | large blocks can cause I/O functions not to respect timeout values due | ||
| 384 | to the time the library takes to transfer blocks to and from the OS | ||
| 385 | and to and from the Lua interpreter. | ||
| 386 | </p> | ||
| 387 | |||
| 388 | <p class=note> | ||
| 389 | Note: The old <tt>timeout</tt> method is deprecated. The name has been | ||
| 390 | changed for sake of uniformity, since all other method names already | ||
| 391 | contained verbs making their imperative nature obvious. | ||
| 392 | </p> | ||
| 393 | |||
| 394 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 395 | |||
| 396 | <div class=footer> | ||
| 397 | <hr> | ||
| 398 | <center> | ||
| 399 | <p class=bar> | ||
| 400 | <a href="home.html">home</a> · | ||
| 401 | <a href="home.html#down">download</a> · | ||
| 402 | <a href="introduction.html">introduction</a> · | ||
| 403 | <a href="reference.html">reference</a> | ||
| 404 | </p> | ||
| 405 | <p> | ||
| 406 | <small> | ||
| 407 | Last modified by Diego Nehab on <br> | ||
| 408 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 409 | </small> | ||
| 410 | </p> | ||
| 411 | </center> | ||
| 412 | </div> | ||
| 413 | |||
| 414 | </body> | ||
| 415 | </html> | ||
diff --git a/doc/udp.html b/doc/udp.html new file mode 100644 index 0000000..235c0c5 --- /dev/null +++ b/doc/udp.html | |||
| @@ -0,0 +1,400 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | <head> | ||
| 5 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 6 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 7 | </head> | ||
| 8 | <body> | ||
| 9 | |||
| 10 | <!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 11 | |||
| 12 | <div class=header> | ||
| 13 | <hr> | ||
| 14 | <center> | ||
| 15 | <table summary="LuaSocket logo"> | ||
| 16 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 17 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 18 | </a></td></tr> | ||
| 19 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 20 | </td></tr> | ||
| 21 | </table> | ||
| 22 | <p class=bar> | ||
| 23 | <a href="home.html">home</a> · | ||
| 24 | <a href="home.html#download">download</a> · | ||
| 25 | <a href="introduction.html">introduction</a> · | ||
| 26 | <a href="reference.html">reference</a> | ||
| 27 | </p> | ||
| 28 | </center> | ||
| 29 | <hr> | ||
| 30 | </div> | ||
| 31 | |||
| 32 | <!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 33 | |||
| 34 | <p class="name" id="socket.udp"> | ||
| 35 | socket.<b>udp()</b> | ||
| 36 | </p> | ||
| 37 | |||
| 38 | <p class="description"> | ||
| 39 | Creates and returns an unconnected UDP object. Unconnected objects support the | ||
| 40 | <a href="#sendto"><tt>sendto</tt></a>, | ||
| 41 | <a href="#receive"><tt>receive</tt></a>, | ||
| 42 | <a href="#receivefrom"><tt>receivefrom</tt></a>, | ||
| 43 | <a href="#getsockname"><tt>getsockname</tt></a>, | ||
| 44 | <a href="#setoption"><tt>setoption</tt></a>, | ||
| 45 | <a href="#settimeout"><tt>settimeout</tt></a>, | ||
| 46 | <a href="#setpeername"><tt>setpeername</tt></a>, | ||
| 47 | <a href="#setsockname"><tt>setsockname</tt></a>, and | ||
| 48 | <a href="#close"><tt>close</tt></a>. | ||
| 49 | The <a href="#setpeername"><tt>setpeername</tt></a> | ||
| 50 | is used to connect the object. | ||
| 51 | </p> | ||
| 52 | |||
| 53 | <p class="return"> | ||
| 54 | In case of success, a new unconnected UDP object | ||
| 55 | returned. In case of error, <tt>nil</tt> is returned, followed by | ||
| 56 | an error message. | ||
| 57 | </p> | ||
| 58 | |||
| 59 | <!-- close +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 60 | |||
| 61 | <p class="name" id="close"> | ||
| 62 | connected:<b>close()</b><br> | ||
| 63 | unconnected:<b>close()</b> | ||
| 64 | </p> | ||
| 65 | |||
| 66 | <p class="description"> | ||
| 67 | Closes a UDP object. The internal socket | ||
| 68 | used by the object is closed and the local address to which the | ||
| 69 | object was bound is made available to other applications. No | ||
| 70 | further operations (except for further calls to the <tt>close</tt> | ||
| 71 | method) are allowed on a closed socket. | ||
| 72 | </p> | ||
| 73 | |||
| 74 | <p class="note"> | ||
| 75 | Note: It is important to close all used sockets | ||
| 76 | once they are not needed, since, in many systems, each socket uses | ||
| 77 | a file descriptor, which are limited system resources. | ||
| 78 | Garbage-collected objects are automatically closed before | ||
| 79 | destruction, though. | ||
| 80 | </p> | ||
| 81 | |||
| 82 | <!-- getpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 83 | |||
| 84 | <p class="name" id="getpeername"> | ||
| 85 | connected:<b>getpeername()</b> | ||
| 86 | </p> | ||
| 87 | |||
| 88 | <p class="description"> | ||
| 89 | Retrieves information about the peer | ||
| 90 | associated with a connected UDP object. | ||
| 91 | </p> | ||
| 92 | |||
| 93 | <p class="return"> | ||
| 94 | Returns the IP address and port number of the peer. | ||
| 95 | </p> | ||
| 96 | |||
| 97 | <p class="note"> | ||
| 98 | Note: It makes no sense to call this method on unconnected objects. | ||
| 99 | </p> | ||
| 100 | |||
| 101 | <!-- getsockname +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 102 | |||
| 103 | <p class="name" id="getsockname"> | ||
| 104 | connected:<b>getsockname()</b><br> | ||
| 105 | unconnected:<b>getsockname()</b> | ||
| 106 | </p> | ||
| 107 | |||
| 108 | <p class="description"> | ||
| 109 | Returns the local address information associated to the object. | ||
| 110 | </p> | ||
| 111 | |||
| 112 | <p class="return"> | ||
| 113 | The method returns a string with local IP | ||
| 114 | address and a number with the port. In case of error, the method | ||
| 115 | returns <tt>nil</tt>. | ||
| 116 | </p> | ||
| 117 | |||
| 118 | <p class="note"> | ||
| 119 | Note: UDP sockets are not bound to any address | ||
| 120 | until the <a href="#setsockname"><tt>setsockname</tt></a> or the | ||
| 121 | <a href="#sendto"><tt>sendto</tt></a> method is called for the | ||
| 122 | first time (in which case it is bound to an ephemeral port and the | ||
| 123 | wild-card address). | ||
| 124 | </p> | ||
| 125 | |||
| 126 | <!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 127 | |||
| 128 | <p class="name" id="receive"> | ||
| 129 | connected:<b>receive(</b>[size]<b>)</b><br> | ||
| 130 | unconnected:<b>receive(</b>[size]<b>)</b> | ||
| 131 | </p> | ||
| 132 | |||
| 133 | <p class="description"> | ||
| 134 | Receives a datagram from the UDP object. If | ||
| 135 | the UDP object is connected, only datagrams coming from the peer | ||
| 136 | are accepted. Otherwise, the returned datagram can come from any | ||
| 137 | host. | ||
| 138 | </p> | ||
| 139 | |||
| 140 | <p class="parameters"> | ||
| 141 | The optional <tt>size</tt> parameter | ||
| 142 | specifies the maximum size of the datagram to be retrieved. If | ||
| 143 | there are more than <tt>size</tt> bytes available in the datagram, | ||
| 144 | the excess bytes are discarded. If there are less then | ||
| 145 | <tt>size</tt> bytes available in the current datagram, the | ||
| 146 | available bytes are returned. If <tt>size</tt> is omitted, the | ||
| 147 | maximum datagram size is used. | ||
| 148 | </p> | ||
| 149 | |||
| 150 | <p class="return"> | ||
| 151 | In case of success, the method return the | ||
| 152 | received datagram. In case of timeout, the method returns | ||
| 153 | <tt>nil</tt> followed by the string '<tt>timeout</tt>'. | ||
| 154 | </p> | ||
| 155 | |||
| 156 | <!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 157 | |||
| 158 | <p class="name" id="receivefrom"> | ||
| 159 | unconnected:<b>receivefrom(</b>[size]<b>)</b> | ||
| 160 | </p> | ||
| 161 | |||
| 162 | <p class="description"> | ||
| 163 | Works exactly as the <a href="#receive"><tt>receive</tt></a> | ||
| 164 | method, except it returns the IP | ||
| 165 | address and port as extra return values (and is therefore slightly less | ||
| 166 | efficient). | ||
| 167 | </p> | ||
| 168 | |||
| 169 | <!-- send ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 170 | |||
| 171 | <p class="name" id="send"> | ||
| 172 | connected:<b>send(</b>datagram<b>)</b> | ||
| 173 | </p> | ||
| 174 | |||
| 175 | <p class="description"> | ||
| 176 | Sends a datagram to the UDP peer of a connected object. | ||
| 177 | </p> | ||
| 178 | |||
| 179 | <p class="parameters"> | ||
| 180 | <tt>Datagram</tt> is a string with the datagram contents. | ||
| 181 | Beware that the maximum datagram size for UDP is 576 bytes. | ||
| 182 | </p> | ||
| 183 | |||
| 184 | <p class="return"> | ||
| 185 | If successful, the method returns 1. In case of | ||
| 186 | error, the method returns <tt>nil</tt> followed by the | ||
| 187 | '<tt>refused</tt>' message. | ||
| 188 | </p> | ||
| 189 | |||
| 190 | <p class="note"> | ||
| 191 | Note: In UDP, the <tt>send</tt> method never blocks | ||
| 192 | and the only way it can fail is if the underlying transport layer | ||
| 193 | refuses to send a message to the specified address (i.e. no | ||
| 194 | interface accepts the address). | ||
| 195 | </p> | ||
| 196 | |||
| 197 | <!-- sendto ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 198 | |||
| 199 | <p class="name" id="sendto"> | ||
| 200 | unconnected:<b>sendto(</b>datagram, ip, port<b>)</b> | ||
| 201 | </p> | ||
| 202 | |||
| 203 | <p class="description"> | ||
| 204 | Sends a datagram to the specified IP address and port number. | ||
| 205 | </p> | ||
| 206 | |||
| 207 | <p class="parameters"> | ||
| 208 | <tt>Datagram</tt> is a string with the | ||
| 209 | datagram contents. Beware that the maximum datagram size for UDP is | ||
| 210 | 576 bytes. <tt>Ip</tt> is the IP address of the recipient. Host | ||
| 211 | names are <em>not</em> allowed for performance reasons. | ||
| 212 | <tt>Port</tt> is the port number at the recipient. | ||
| 213 | </p> | ||
| 214 | |||
| 215 | <p class="return"> | ||
| 216 | If successful, the method returns 1. In case of | ||
| 217 | error, the method returns <tt>nil</tt> followed by the | ||
| 218 | '<tt>refused</tt>' message. | ||
| 219 | </p> | ||
| 220 | |||
| 221 | <p class="note"> | ||
| 222 | Note: In UDP, the <tt>send</tt> method never blocks | ||
| 223 | and the only way it can fail is if the underlying transport layer | ||
| 224 | refuses to send a message to the specified address (i.e. no | ||
| 225 | interface accepts the address). | ||
| 226 | </p> | ||
| 227 | |||
| 228 | <!-- setpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 229 | |||
| 230 | <p class="name" id="setpeername"> | ||
| 231 | connected:<b>setpeername(</b>'*'<b>)</b><br> | ||
| 232 | unconnected:<b>setpeername(</b>address, port<b>)</b> | ||
| 233 | </p> | ||
| 234 | |||
| 235 | <p class="description"> | ||
| 236 | Changes the peer of a UDP object. This | ||
| 237 | method turns an unconnected UDP object into a connected UDP | ||
| 238 | object or vice-versa. | ||
| 239 | </p> | ||
| 240 | |||
| 241 | <p class="description"> | ||
| 242 | For connected objects, outgoing datagrams | ||
| 243 | will be sent to the specified peer, and datagrams received from | ||
| 244 | other peers will be discarded by the OS. Connected UDP objects must | ||
| 245 | use the <a href="#send"><tt>send</tt></a> and | ||
| 246 | <a href="#receive"><tt>receive</tt></a> methods instead of | ||
| 247 | <a href="#sendto"><tt>sendto</tt></a> and | ||
| 248 | <a href="#receivefrom"><tt>receivefrom</tt></a>. | ||
| 249 | </p> | ||
| 250 | |||
| 251 | <p class="parameters"> | ||
| 252 | <tt>Address</tt> can be an IP address or a | ||
| 253 | host name. <tt>Port</tt> is the port number. If <tt>address</tt> is | ||
| 254 | '<tt>*</tt>' and the object is connected, the peer association is | ||
| 255 | removed and the object becomes an unconnected object again. In that | ||
| 256 | case, the <tt>port</tt> argument is ignored. | ||
| 257 | </p> | ||
| 258 | |||
| 259 | <p class="return"> | ||
| 260 | In case of error the method returns | ||
| 261 | <tt>nil</tt> followed by an error message. In case of success, the | ||
| 262 | method returns 1. | ||
| 263 | </p> | ||
| 264 | |||
| 265 | <p class="note"> | ||
| 266 | Note: Since the address of the peer does not have | ||
| 267 | to be passed to and from the OS, the use of connected UDP objects | ||
| 268 | is recommended when the same peer is used for several transmissions | ||
| 269 | and can result in up to 30% performance gains. | ||
| 270 | </p> | ||
| 271 | |||
| 272 | <!-- setsockname +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 273 | |||
| 274 | <p class="name" id="setsockname"> | ||
| 275 | unconnected:<b>setsockname(</b>address, port<b>)</b> | ||
| 276 | </p> | ||
| 277 | |||
| 278 | <p class="description"> | ||
| 279 | Binds the UDP object to a local address. | ||
| 280 | </p> | ||
| 281 | |||
| 282 | <p class="parameters"> | ||
| 283 | <tt>Address</tt> can be an IP address or a | ||
| 284 | host name. If <tt>address</tt> is '<tt>*</tt>' the system binds to | ||
| 285 | all local interfaces using the constant <tt>INADDR_ANY</tt>. If | ||
| 286 | <tt>port</tt> is 0, the system chooses an ephemeral port. | ||
| 287 | </p> | ||
| 288 | |||
| 289 | <p class="return"> | ||
| 290 | If successful, the method returns 1. In case of | ||
| 291 | error, the method returns <tt>nil</tt> followed by an error | ||
| 292 | message. | ||
| 293 | </p> | ||
| 294 | |||
| 295 | <p class="note"> | ||
| 296 | Note: This method can only be called before any | ||
| 297 | datagram is sent through the UDP object, and only once. Otherwise, | ||
| 298 | the system automatically binds the object to all local interfaces | ||
| 299 | and chooses an ephemeral port as soon as the first datagram is | ||
| 300 | sent. After the local address is set, either automatically by the | ||
| 301 | system or explicitly by <tt>setsockname</tt>, it cannot be | ||
| 302 | changed. | ||
| 303 | </p> | ||
| 304 | |||
| 305 | <!-- setoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 306 | |||
| 307 | <p class="name" id="setoption"> | ||
| 308 | connected:<b>setoption(</b>option [, value]<b>)</b><br> | ||
| 309 | unconnected:<b>setoption(</b>option [, value]<b>)</b> | ||
| 310 | </p> | ||
| 311 | |||
| 312 | <p class="description"> | ||
| 313 | Sets options for the UDP object. Options are | ||
| 314 | only needed by low-level or time-critical applications. You should | ||
| 315 | only modify a an option if you are sure you need it.</p> | ||
| 316 | <p class="parameters"><tt>Option</tt> is a string with the option | ||
| 317 | name, and <tt>value</tt> depends on the option being set: | ||
| 318 | </p> | ||
| 319 | |||
| 320 | <ul> | ||
| 321 | <li>'<tt>dontroute</tt>': Setting this option to <tt>true</tt> | ||
| 322 | indicates that outgoing messages should bypass the standard routing | ||
| 323 | facilities;</li> | ||
| 324 | <li>'<tt>broadcast</tt>': Setting this option to <tt>true</tt> | ||
| 325 | requests permission to send broadcast datagrams on the | ||
| 326 | socket.</li> | ||
| 327 | </ul> | ||
| 328 | |||
| 329 | <p class="return"> | ||
| 330 | The method returns 1 in case of success, or | ||
| 331 | <tt>nil</tt> followed by an error message otherwise. | ||
| 332 | </p> | ||
| 333 | |||
| 334 | <p class="note"> | ||
| 335 | Note: The descriptions above come from the man | ||
| 336 | pages. | ||
| 337 | </p> | ||
| 338 | |||
| 339 | <!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 340 | |||
| 341 | <p class="name" id="settimeout"> | ||
| 342 | connected:<b>settimeout(</b>value<b>)</b><br> | ||
| 343 | unconnected:<b>settimeout(</b>value<b>)</b> | ||
| 344 | </p> | ||
| 345 | |||
| 346 | <p class="description"> | ||
| 347 | Changes the timeout values for the object. By default, the | ||
| 348 | <a href="#receive"><tt>receive</tt></a> and | ||
| 349 | <a href="#receivefrom"><tt>receivefrom</tt></a> | ||
| 350 | operations are blocking. That is, any call to the methods will block | ||
| 351 | indefinitely, until data arrives. The <tt>settimeout</tt> function defines | ||
| 352 | a limit on the amount of time the functions can block. When a timeout is | ||
| 353 | set and the specified amount of time has elapsed, the affected methods | ||
| 354 | give up and fail with an error code. | ||
| 355 | </p> | ||
| 356 | |||
| 357 | <p class="parameters"> | ||
| 358 | The amount of time to wait is specified as | ||
| 359 | the <tt>value</tt> parameter, in seconds. The <tt>nil</tt> timeout | ||
| 360 | <tt>value</tt> allows operations to block indefinitely. Negative | ||
| 361 | timeout values have the same effect. | ||
| 362 | </p> | ||
| 363 | |||
| 364 | <p class="note"> | ||
| 365 | Note: In UDP, the <a href="#send"><tt>send</tt></a> | ||
| 366 | and <a href="#sentdo"><tt>sendto</tt></a> methods never block (the | ||
| 367 | datagram is just passed to the OS and the call returns | ||
| 368 | immediately). Therefore, the <tt>settimeout</tt> method has no | ||
| 369 | effect on them. | ||
| 370 | </p> | ||
| 371 | |||
| 372 | <p class="note"> | ||
| 373 | Note: The old <tt>timeout</tt> method is | ||
| 374 | deprecated. The name has been changed for sake of uniformity, since | ||
| 375 | all other method names already contained verbs making their | ||
| 376 | imperative nature obvious. | ||
| 377 | </p> | ||
| 378 | |||
| 379 | <!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 380 | |||
| 381 | <div class=footer> | ||
| 382 | <hr> | ||
| 383 | <center> | ||
| 384 | <p class=bar> | ||
| 385 | <a href="home.html">home</a> · | ||
| 386 | <a href="home.html#download">download</a> · | ||
| 387 | <a href="introduction.html">introduction</a> · | ||
| 388 | <a href="reference.html">reference</a> | ||
| 389 | </p> | ||
| 390 | <p> | ||
| 391 | <small> | ||
| 392 | Last modified by Diego Nehab on <br> | ||
| 393 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 394 | </small> | ||
| 395 | </p> | ||
| 396 | </center> | ||
| 397 | </div> | ||
| 398 | |||
| 399 | </body> | ||
| 400 | </html> | ||
diff --git a/doc/url.html b/doc/url.html new file mode 100644 index 0000000..e67ea13 --- /dev/null +++ b/doc/url.html | |||
| @@ -0,0 +1,265 @@ | |||
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> | ||
| 3 | <html> | ||
| 4 | |||
| 5 | <head> | ||
| 6 | <title>LuaSocket: Network support for the Lua language</title> | ||
| 7 | <link rel="stylesheet" href="reference.css" type="text/css"> | ||
| 8 | </head> | ||
| 9 | |||
| 10 | <body> | ||
| 11 | |||
| 12 | <!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 13 | |||
| 14 | <div class=header> | ||
| 15 | <hr> | ||
| 16 | <center> | ||
| 17 | <table summary="LuaSocket logo"> | ||
| 18 | <tr><td align=center><a href="http://www.lua.org"> | ||
| 19 | <img border=0 alt="LuaSocket" src="luasocket.png"> | ||
| 20 | </a></td></tr> | ||
| 21 | <tr><td align=center valign=top>Network support for the Lua language | ||
| 22 | </td></tr> | ||
| 23 | </table> | ||
| 24 | <p class=bar> | ||
| 25 | <a href="home.html">home</a> · | ||
| 26 | <a href="home.html#download">download</a> · | ||
| 27 | <a href="introduction.html">introduction</a> · | ||
| 28 | <a href="reference.html">reference</a> | ||
| 29 | </p> | ||
| 30 | </center> | ||
| 31 | <hr> | ||
| 32 | </div> | ||
| 33 | |||
| 34 | <!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 35 | |||
| 36 | <h2 id=url>URL</h2> | ||
| 37 | |||
| 38 | <p> | ||
| 39 | The module <tt>url.lua</tt> provides functions to parse, protect, | ||
| 40 | and build URLs, as well as functions to compose absolute URLs | ||
| 41 | from base and relative URLs, according to | ||
| 42 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC | ||
| 43 | 2396</a>. | ||
| 44 | </p> | ||
| 45 | |||
| 46 | <p> | ||
| 47 | An URL is defined by the following grammar: | ||
| 48 | </p> | ||
| 49 | |||
| 50 | <blockquote> | ||
| 51 | <tt> | ||
| 52 | <url> ::= [<scheme>:][//<authority>][/<path>][;<params>][?<query>][#<fragment>]<br> | ||
| 53 | <authority> ::= [<userinfo>@]<host>[:<port>]<br> | ||
| 54 | <userinfo> ::= <user>[:<password>]<br> | ||
| 55 | <path> ::= {<segment>/}<segment><br> | ||
| 56 | </tt> | ||
| 57 | </blockquote> | ||
| 58 | |||
| 59 | <!-- absolute +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 60 | |||
| 61 | <p class=name id=absolute> | ||
| 62 | socket.url.<b>absolute(</b>base, relative<b>)</b> | ||
| 63 | </p> | ||
| 64 | |||
| 65 | <p class=description> | ||
| 66 | Builds an absolute URL from a base URL and a relative URL. | ||
| 67 | </p> | ||
| 68 | |||
| 69 | <p class=parameters> | ||
| 70 | <tt>Base</tt> is a string with the base URL and <tt>relative</tt> is a | ||
| 71 | string with the relative URL. | ||
| 72 | </p> | ||
| 73 | |||
| 74 | <p class=return> | ||
| 75 | The function returns a string with the absolute URL. | ||
| 76 | </p> | ||
| 77 | |||
| 78 | <p class=note> | ||
| 79 | Note: The rules that | ||
| 80 | govern the composition are fairly complex, and are described in detail in | ||
| 81 | <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC 2396</a>. | ||
| 82 | The example bellow should give an idea of what are the rules. | ||
| 83 | </p> | ||
| 84 | |||
| 85 | <pre class=example> | ||
| 86 | http://a/b/c/d;p?q | ||
| 87 | |||
| 88 | + | ||
| 89 | |||
| 90 | g:h = g:h | ||
| 91 | g = http://a/b/c/g | ||
| 92 | ./g = http://a/b/c/g | ||
| 93 | g/ = http://a/b/c/g/ | ||
| 94 | /g = http://a/g | ||
| 95 | //g = http://g | ||
| 96 | ?y = http://a/b/c/?y | ||
| 97 | g?y = http://a/b/c/g?y | ||
| 98 | #s = http://a/b/c/d;p?q#s | ||
| 99 | g#s = http://a/b/c/g#s | ||
| 100 | g?y#s = http://a/b/c/g?y#s | ||
| 101 | ;x = http://a/b/c/;x | ||
| 102 | g;x = http://a/b/c/g;x | ||
| 103 | g;x?y#s = http://a/b/c/g;x?y#s | ||
| 104 | . = http://a/b/c/ | ||
| 105 | ./ = http://a/b/c/ | ||
| 106 | .. = http://a/b/ | ||
| 107 | ../ = http://a/b/ | ||
| 108 | ../g = http://a/b/g | ||
| 109 | ../.. = http://a/ | ||
| 110 | ../../ = http://a/ | ||
| 111 | ../../g = http://a/g | ||
| 112 | </pre> | ||
| 113 | |||
| 114 | <!-- build ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 115 | |||
| 116 | <p class=name id=build> | ||
| 117 | socket.url.<b>build(</b>parsed_url<b>)</b> | ||
| 118 | </p> | ||
| 119 | |||
| 120 | <p class=description> | ||
| 121 | Rebuilds an URL from its parts. | ||
| 122 | </p> | ||
| 123 | |||
| 124 | <p class=parameters> | ||
| 125 | <tt>Parsed_url</tt> is a table with same components returned by | ||
| 126 | <a href="#parse"><tt>parse</tt></a>. | ||
| 127 | Lower level components, if specified, | ||
| 128 | take precedence over hight level components of the URL grammar. | ||
| 129 | </p> | ||
| 130 | |||
| 131 | <p class=return> | ||
| 132 | The function returns a string with the built URL. | ||
| 133 | </p> | ||
| 134 | |||
| 135 | <!-- build_path +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 136 | |||
| 137 | <p class=name id=build_path> | ||
| 138 | socket.url.<b>build_path(</b>segments, unsafe<b>)</b> | ||
| 139 | </p> | ||
| 140 | |||
| 141 | <p class=description> | ||
| 142 | Builds a <tt><path></tt> component from a list of | ||
| 143 | <tt><segment></tt> parts. | ||
| 144 | Before composition, any reserved characters found in a segment are escaped into | ||
| 145 | their protected form, so that the resulting path is a valid URL path | ||
| 146 | component. | ||
| 147 | </p> | ||
| 148 | |||
| 149 | <p class=parameters> | ||
| 150 | <tt>Segments</tt> is a list of strings with the <tt><segment></tt> | ||
| 151 | parts. If <tt>unsafe</tt> is anything but <tt>nil</tt>, reserved | ||
| 152 | characters are left untouched. | ||
| 153 | </p> | ||
| 154 | |||
| 155 | <p class=return> | ||
| 156 | The function returns a string with the | ||
| 157 | built <tt><path></tt> component. | ||
| 158 | </p> | ||
| 159 | |||
| 160 | <!-- parse ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 161 | |||
| 162 | <p class=name id=parse> | ||
| 163 | socket.url.<b>parse(</b>url, default<b>)</b> | ||
| 164 | </p> | ||
| 165 | |||
| 166 | <p class=description> | ||
| 167 | Parses an URL given as a string into a Lua table with its components. | ||
| 168 | </p> | ||
| 169 | |||
| 170 | <p class=parameters> | ||
| 171 | <tt>Url</tt> is the URL to be parsed. If the <tt>default</tt> table is | ||
| 172 | present, it is used to store the parsed fields. Only fields present in the | ||
| 173 | URL are overwritten. Therefore, this table can be used to pass default | ||
| 174 | values for each field. | ||
| 175 | </p> | ||
| 176 | |||
| 177 | <p class=return> | ||
| 178 | The function returns a table with all the URL components: | ||
| 179 | </p> | ||
| 180 | |||
| 181 | <blockquote><tt> | ||
| 182 | parsed_url = {<br> | ||
| 183 | url = <i>string</i>,<br> | ||
| 184 | scheme = <i>string</i>,<br> | ||
| 185 | authority = <i>string</i>,<br> | ||
| 186 | path = <i>string</i>,<br> | ||
| 187 | params = <i>string</i>,<br> | ||
| 188 | query = <i>string</i>,<br> | ||
| 189 | fragment = <i>string</i>,<br> | ||
| 190 | userinfo = <i>string</i>,<br> | ||
| 191 | host = <i>string</i>,<br> | ||
| 192 | port = <i>string</i>,<br> | ||
| 193 | user = <i>string</i>,<br> | ||
| 194 | password = <i>string</i><br> | ||
| 195 | } | ||
| 196 | </tt></blockquote> | ||
| 197 | |||
| 198 | <pre class=example> | ||
| 199 | parsed_url = socket.url.parse("http://www.puc-rio.br/~diego/index.lua?a=2#there") | ||
| 200 | -- parsed_url = { | ||
| 201 | -- scheme = "http", | ||
| 202 | -- authority = "www.puc-rio.br", | ||
| 203 | -- path = "/~diego/index.lua" | ||
| 204 | -- query = "a=2", | ||
| 205 | -- fragment = "there", | ||
| 206 | -- host = "www.puc-rio.br", | ||
| 207 | -- } | ||
| 208 | |||
| 209 | parsed_url = socket.url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i") | ||
| 210 | -- parsed_url = { | ||
| 211 | -- scheme = "ftp", | ||
| 212 | -- authority = "root:passwd@unsafe.org", | ||
| 213 | -- path = "/pub/virus.exe", | ||
| 214 | -- params = "type=i", | ||
| 215 | -- userinfo = "root:passwd", | ||
| 216 | -- host = "unsafe.org", | ||
| 217 | -- user = "root", | ||
| 218 | -- password = "passwd", | ||
| 219 | -- } | ||
| 220 | </pre> | ||
| 221 | |||
| 222 | <!-- parse_path +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 223 | |||
| 224 | <p class=name id=parse_path> | ||
| 225 | socket.url.<b>parse_path(</b>path<b>)</b> | ||
| 226 | </p> | ||
| 227 | |||
| 228 | <p class=description> | ||
| 229 | Breaks a <tt><path></tt> URL component into all its | ||
| 230 | <tt><segment></tt> parts. | ||
| 231 | </p> | ||
| 232 | |||
| 233 | <p class=description> | ||
| 234 | <tt>Path</tt> is a string with the path to be parsed. | ||
| 235 | </p> | ||
| 236 | |||
| 237 | <p class=return> | ||
| 238 | Since some characters are reserved in URLs, they must be escaped | ||
| 239 | whenever present in a <tt><path></tt> component. Therefore, before | ||
| 240 | returning a list with all the parsed segments, the function unescapes all | ||
| 241 | of them. | ||
| 242 | </p> | ||
| 243 | |||
| 244 | <!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
| 245 | |||
| 246 | <div class=footer> | ||
| 247 | <hr> | ||
| 248 | <center> | ||
| 249 | <p class=bar> | ||
| 250 | <a href="home.html">home</a> · | ||
| 251 | <a href="home.html#down">download</a> · | ||
| 252 | <a href="introduction.html">introduction</a> · | ||
| 253 | <a href="reference.html">reference</a> | ||
| 254 | </p> | ||
| 255 | <p> | ||
| 256 | <small> | ||
| 257 | Last modified by Diego Nehab on <br> | ||
| 258 | Sat Aug 9 01:00:41 PDT 2003 | ||
| 259 | </small> | ||
| 260 | </p> | ||
| 261 | </center> | ||
| 262 | </div> | ||
| 263 | |||
| 264 | </body> | ||
| 265 | </html> | ||
