mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Added description for the connect() socket interface
This commit is contained in:
1 parent
faa030385c
commit
30f71a8bc4
1 file changed
+17
@@ -340,6 +340,23 @@ Mongoose exports the following to the Lua server page:
|
|||||||
mg.version -- a string that holds Mongoose version
|
mg.version -- a string that holds Mongoose version
|
||||||
mg.request_info -- a table with request information
|
mg.request_info -- a table with request information
|
||||||
|
|
||||||
|
-- Connect to the remote TCP server. This function is an implementation
|
||||||
|
-- of simple socket interface. It returns a socket object with three
|
||||||
|
-- methods: send, recv, close, which are synchronous (blocking).
|
||||||
|
-- connect() throws an exception on connection error.
|
||||||
|
connect(host, port, use_ssl)
|
||||||
|
|
||||||
|
-- Example of using connect() interface:
|
||||||
|
local host = 'code.google.com' -- IP address or domain name
|
||||||
|
local ok, sock = pcall(connect, host, 80, 1)
|
||||||
|
if ok then
|
||||||
|
sock:send('GET /p/mongoose/ HTTP/1.0\r\n' ..
|
||||||
|
'Host: ' .. host .. '\r\n\r\n')
|
||||||
|
local reply = sock:recv()
|
||||||
|
sock:close()
|
||||||
|
-- reply now contains the web page https://code.google.com/p/mongoose
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
**IMPORTANT: Mongoose does not send HTTP headers for Lua pages. Therefore,
|
**IMPORTANT: Mongoose does not send HTTP headers for Lua pages. Therefore,
|
||||||
every Lua Page must begin with HTTP reply line and headers**, like this:
|
every Lua Page must begin with HTTP reply line and headers**, like this:
|
||||||
|
|||||||
Reference in new issue
Block a user