luasocket

測試luasocket


更新記錄

item note
20160816 第一版

目錄


LuaSocket

LuaSocket is a Lua extension library that is composed by two parts:

  • a C core that provides support for the TCP and UDP transport layers
1
2
/local/lib/lua/5.1/mime/core.so
/local/lib/lua/5.1/socket/core.so
  • and a set of Lua modules that add support for functionality commonly needed by applications that deal with the Internet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
./local/share/lua/5.1/ltn12.lua
./local/share/lua/5.1/socket.lua
./local/share/lua/5.1/socket/headers.lua
./local/share/lua/5.1/socket/tp.lua
./local/share/lua/5.1/socket/http.lua
./local/share/lua/5.1/socket/ftp.lua
./local/share/lua/5.1/socket/url.lua
./local/share/lua/5.1/socket/smtp.lua
./local/share/lua/5.1/mime.lua
```

### 顯示LuaSocket版本

``Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> socket = require("socket")
> print(socket._VERSION)
LuaSocket 3.0-rc1
`

http example

  • http.request()

  • api example

  • [luasocket-3.0-rc1/doc/http.html1
1
2
3
4
5
6
7
8
9
10
11
12
http.request(url [, body])
http.request{
url = string,
[sink = LTN12 sink,]
[method = string,]
[headers = header-table,]
[source = LTN12 source],
[step = LTN12 pump step,]
[proxy = string,]
[redirect = boolean,]
[create = function]
}
  • test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> require ("socket")
> socket = require("socket")
> print(socket._VERSION)
LuaSocket 3.0-rc1
>
> http = require("socket.http")
> print(http.request("http://www.impa.br/~diego/software/luasocket"))
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<meta name="description" content="The LuaSocket Homepage">
<meta name="keywords" content="Lua, LuaSocket, Network, Library, Support, Internet">
<title>LuaSocket: Network support for the Lua language </title>
<link rel="stylesheet" href="reference.css" type="text/css">
</head>

<body>
xxx

Reference

item note
DNS getaddrinfo, gethostname, tohostname, toip.
FTP get, put.
HTTP request.
LTN12 filter: chain, cycle.
pump: all, step.
sink: chain, error, file, null, simplify, table.
source: cat, chain, empty, error, file, simplify, string.
MIME high-level: decode, encode, normalize, stuff, wrap.
low-level: b64, dot, eol, qp, qpwrp, unb64, unqp, wrp.
SMTP message, send.
Socket bind, connect, connect4, connect6, _DEBUG, dns, gettime, headers.canonic, newtry, protect, select, sink, skip, sleep,
_SETSIZE, source, tcp, tcp6, try, udp, udp6, _VERSION.
TCP (in socket) accept, bind, close, connect, dirty, getfd, getoption, getpeername, getsockname, getstats, listen, receive
send, setfd, setoption, setstats, settimeout, shutdown.
UDP (in socket) close, getoption, getpeername, getsockname, receive, receivefrom, send, sendto, setpeername, setsockname, setoption, settimeout.
URL absolute, build, build_path, escape, parse, parse_path, unescape.

參考來源