浏览代码

Added description for the connect() socket interface

Sergey Lyubka 12 年之前
父节点
当前提交
30f71a8bc4
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      UserManual.md

+ 17 - 0
UserManual.md

@@ -340,6 +340,23 @@ Mongoose exports the following to the Lua server page:
     mg.version        -- a string that holds Mongoose version
     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,
 every Lua Page must begin with HTTP reply line and headers**, like this: