标签:style class blog code http tar
xavante是一个使用lua实现的遵守http1.1的web server,支持wsapi。
依赖库:
xavante核心 -- lua, copas(纯lua编写,网络连接coroutine处理), luasocket处理网络连接。
xavante file handler -- luaFileSystem
此项目属于kepler项目的一个子项目,见官网地址:
http://keplerproject.github.io/xavante/manual.html
github上维护开源代码:
https://github.com/keplerproject/xavante
xavante提供三类处理接口:
URL映射, 文件上传, 和 CGIlua调用,配置运行步骤 见官网介绍:
http://keplerproject.github.io/xavante/manual.html#install
xavante是以一个库的形式存在,如果想运行必须下载wsapi。
wsapi是从web应用中抽象出来的web server接口, 按照wsapi接口编程的web应用程序具有可移植性,
可以再不同的服务器上运行, 包括 CGI FASTCGI XAVANTE
主要负责,请求处理 和 输出缓存, 详情见官网:
http://keplerproject.github.io/wsapi/index.html
安装运行:
http://keplerproject.github.io/wsapi/manual.html
接口说明文档:
http://keplerproject.github.io/wsapi/libraries.html
lua for windows 是一个包含了很多lua库的安装包,
包括 luaExpat luaSocket luaFileSystem Copas Rings 等库,
其中Copas为xavante依赖的库;
luaExpat 和 luaSocket为lua-xmlrpc依赖库。
http://code.google.com/p/luaforwindows/downloads/list
client.lua
require("xmlrpc.http") -- hello_world local ok, res = xmlrpc.http.call("http://localhost:12345", "hello_world") assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res))) print("Result: " .. tostring(res)) -- add number local ok, res = xmlrpc.http.call("http://localhost:12345", "add", 1, 2) assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res))) print("Result: " .. tostring(res))
server_xavante.lua
xavante = require("xavante") wsapi = require("wsapi") wsapi.xavante = require("wsapi.xavante") wsapi.request = require("wsapi.request") require("xmlrpc") --- XML-RPC WSAPI handler -- @param wsapi_env WSAPI environment function wsapi_handler(wsapi_env) local headers = { ["Content-type"] = "text/xml" } local req = wsapi.request.new(wsapi_env) local method, arg_table = xmlrpc.srvDecode(req.POST.post_data) local func = xmlrpc.dispatch(method) local result = { pcall(func, unpack(arg_table or {})) } local ok = result[1] if not ok then result = { code = 3, message = result[2] } else table.remove(result, 1) if table.getn(result) == 1 then result = result[1] end end local r = xmlrpc.srvEncode(result, not ok) headers["Content-length"] = tostring(#r) local function xmlrpc_reply(wsapienv) coroutine.yield(r) end return 200, headers, coroutine.wrap(xmlrpc_reply) end -- XML-RPC exported functions xmlrpc_exports = {} --- Get simple string. -- @return simple string function xmlrpc_exports.hello_world() return "Hello World" end --- add two number function. -- @return sum function xmlrpc_exports.add(a, b) return a + b end local rules = {{ match = ".", with = wsapi.xavante.makeHandler(wsapi_handler) }} local config = { server = {host = "*", port = 12345}, defaultHost = { rules = rules} } xmlrpc.srvMethods(xmlrpc_exports) xavante.HTTP(config) xavante.start()
Lua xavante WEB server实现xmlrpc服务器端,布布扣,bubuko.com
Lua xavante WEB server实现xmlrpc服务器端
标签:style class blog code http tar
原文地址:http://www.cnblogs.com/lightsong/p/3779018.html