Lua xavante WEB server实现xmlrpc服务器端
xavante
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
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 xml rpc 访问xavante提供的xmlrpc service
- 下载安装 lua for windows
lua for windows 是一个包含了很多lua库的安装包,
包括 luaExpat luaSocket luaFileSystem Copas Rings 等库,
其中Copas为xavante依赖的库;
luaExpat 和 luaSocket为lua-xmlrpc依赖库。
http://code.google.com/p/luaforwindows/downloads/list
- xavante安装
- 将解压后的xavante文件夹中src的xavante目录拖到lua.exe同级,
- 并文件夹中的xavante.lua拖出来与lua.exe同级。
- wsapi安装
- 将加压后的wsapi文件夹中的src的 wsapi 目录和 wsapi.lua 文件拖到lua.exe同级。
- 将lua-xmlrpc加压后的 src文件放到 xmlrpc目录中(与lua.exe同级)
- 将 lua-xmlrpc 的 client.lua 和 server-xavante.lua 添加add加法rpc调用,放到lua.exe同级。
代码:
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", , )
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[]
if not ok then
result = { code = , message = result[] }
else
table.remove(result, )
if table.getn(result) == then
result = result[]
end
end
local r = xmlrpc.srvEncode(result, not ok)
headers["Content-length"] = tostring(#r)
local function xmlrpc_reply(wsapienv) coroutine.yield(r)
end
return , 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 = }, defaultHost = { rules = rules} } xmlrpc.srvMethods(xmlrpc_exports) xavante.HTTP(config) xavante.start()
Lua xavante WEB server实现xmlrpc服务器端的更多相关文章
- 【轮子狂魔】抛弃IIS,打造个性的Web Server - WebAPI/Lua/MVC(附带源码)
引言 此篇是<[轮子狂魔]抛弃IIS,向天借个HttpListener - 基础篇(附带源码)>的续篇,也可以说是提高篇,如果你对HttpListener不甚了解的话,建议先看下基础篇. ...
- The Python web services developer: XML-RPC for Python
原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...
- Chapter 1: A Simple Web Server
这算是一篇读书笔记,留着以后复习看看. Web Server又称为Http Server,因为它使用HTTP协议和客户端(一般是各种各样的浏览器)进行通信. 什么是HTTP协议呢? HTTP协议是基于 ...
- 小测几种python web server的性能
http://blog.csdn.net/raptor/article/details/8038476 因为换了nginx就不再使用mod_wsgi来跑web.py应用了,现在用的是gevent-ws ...
- web server服务器
使用最多的 web server服务器软件有两个:微软的信息服务器(iis),和Apache. 通俗的讲,Web服务器传送(serves)页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序 ...
- C# .net基于Http实现web server(web服务)
原文:C# .net基于Http实现web server(web服务) 什么是 web server? 百度百科是这么解释的: Web Server中文名称叫网页服务器或web服务器.WEB服务器也 ...
- [随笔][胡思乱想][唠叨][web server]
nginx是一个webserver,最基本的功能是发送静态的文件.类似于apache2的webserver,主要的功能就是响应请求,做出响应. 所说的服务器是安装了服务器软件的物理机,专用的服务器或者 ...
- 动态 Web Server 技术发展历程
动态 Web Server 技术发展历程 开始接触 Java Web 方面的技术,此篇文章是以介绍 Web server 相关技术的演变为主来作为了解 Java servlet 的技术背景,目的是更好 ...
- 简易web server之python实现
网络编程一项基本功是socket编程,包括TCP socket,UDP socket的客户端.服务器端编程. 应用层的各路协议如http,smtp,telnet,ftp等都依赖于传输层的TCP或者UD ...
随机推荐
- A trip through the Graphics Pipeline 2011_03
At this point, we’ve sent draw calls down from our app all the way through various driver layers and ...
- VMware 虚拟机使用 NAT 方式联网
选择要设置的虚拟主机: 点击右键,选择 “属性”,查看 “网络适配器”: 此时选择的连接方式是 “Host-only”,在 Host-only 模式中,所有的虚拟系统是可以相互通信的,但虚拟系统和真实 ...
- jquery.cookie.js 的使用
jquery.cookie.js 对cookie的操作 $.cookie('the_cookie'); //读取Cookie值 $.cookie('the_cookie', 'the_value'); ...
- PHP 随机显示
<?php print_r( array_rand( array( "新春快乐"=>"", " ...
- 3.PHP内核探索:一次请求生命周期
我们从未手动开启过PHP的相关进程,它是随着Apache的启动而运行的.PHP通过mod_php5.so模块和Apache相连(具体说来是SAPI,即服务器应用程序编程接口). PHP总共有三个模块: ...
- coursera-miniproject stopwatch任务总结
---恢复内容开始--- 首先是miniproject的说明: combin text drawing in canvas with time to build digital stopwatch. ...
- mysql中文字段转拼音首字母,以及中文拼音模糊查询
创建存储过程,将中文字段转拼音首字母 CREATE DEFINER=`root`@`%` FUNCTION `fristPinyin`(P_NAME VARCHAR(255)) RETURNS var ...
- vimtutor
================================================================================ 欢 迎 阅 读 < V I M ...
- spring容器IOC创建对象<三>
问题?Spring的DI讲解.DI有几种注入方式.一.spring的DI:依赖注入给属性赋值DI定义:一个对象类的属性可以使用springDI(依赖注入)来进行赋值,但是并不是所有的类属性都适合spr ...
- fatal error C1854: 无法覆盖在创建对象文件.obj”的预编译头过程中形成的信息
原因: 将stdafx.cpp 的预编译头属性 由 创建预编译头(/Yc) 改成了 使用预编译头(/Yu) 解决: 改回为 创建预编译头(/Yc) 参考文档 http://blog.csdn.net ...