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服务器端的更多相关文章

  1. 【轮子狂魔】抛弃IIS,打造个性的Web Server - WebAPI/Lua/MVC(附带源码)

    引言 此篇是<[轮子狂魔]抛弃IIS,向天借个HttpListener - 基础篇(附带源码)>的续篇,也可以说是提高篇,如果你对HttpListener不甚了解的话,建议先看下基础篇. ...

  2. The Python web services developer: XML-RPC for Python

    原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...

  3. Chapter 1: A Simple Web Server

    这算是一篇读书笔记,留着以后复习看看. Web Server又称为Http Server,因为它使用HTTP协议和客户端(一般是各种各样的浏览器)进行通信. 什么是HTTP协议呢? HTTP协议是基于 ...

  4. 小测几种python web server的性能

    http://blog.csdn.net/raptor/article/details/8038476 因为换了nginx就不再使用mod_wsgi来跑web.py应用了,现在用的是gevent-ws ...

  5. web server服务器

    使用最多的 web server服务器软件有两个:微软的信息服务器(iis),和Apache. 通俗的讲,Web服务器传送(serves)页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序 ...

  6. C# .net基于Http实现web server(web服务)

    原文:C# .net基于Http实现web server(web服务) 什么是 web server?  百度百科是这么解释的: Web Server中文名称叫网页服务器或web服务器.WEB服务器也 ...

  7. [随笔][胡思乱想][唠叨][web server]

    nginx是一个webserver,最基本的功能是发送静态的文件.类似于apache2的webserver,主要的功能就是响应请求,做出响应. 所说的服务器是安装了服务器软件的物理机,专用的服务器或者 ...

  8. 动态 Web Server 技术发展历程

    动态 Web Server 技术发展历程 开始接触 Java Web 方面的技术,此篇文章是以介绍 Web server 相关技术的演变为主来作为了解 Java servlet 的技术背景,目的是更好 ...

  9. 简易web server之python实现

    网络编程一项基本功是socket编程,包括TCP socket,UDP socket的客户端.服务器端编程. 应用层的各路协议如http,smtp,telnet,ftp等都依赖于传输层的TCP或者UD ...

随机推荐

  1. gitlab & gerrit & git & repo & jenkins

    Omnibus GitLab documentation(中文安装说明) 在自己的服务器上部署 GitLab 社区版->较为全面 GIT & REPO & GERRIT (三) ...

  2. [项目机会]citrix 虚拟桌面对于java等高CPU占用率如何解决

    citrix 虚拟桌面对于java等高CPU占用率如何解决 问题1:java等客户端对于虚拟桌面cpu影响较大,但是有些用户的确需要使用java支持的程序,是否可以通过其他途径来解决? 问题2:对于其 ...

  3. [ZZ] D3D中的模板缓存(3)

    http://www.cppblog.com/lovedday/archive/2008/03/25/45334.html http://www.cppblog.com/lovedday/ D3D中的 ...

  4. UIButton的遍历

    for (id obj in self.view.subviews) {                if ([obj isKindOfClass:[UIButton class]]) {      ...

  5. UE4.7的IOS发布和调试的相关问题

    UE4.7以后正式源码免费了,正好最近工作也在做这部分,ue4的官方文档虽然有一部分ios平台的资料,那也只是通过编辑器来发布或预览一类,但手游程序员都知道,一些cpu和gpu性能上的调试是在所难免的 ...

  6. C++类型转化分析(1)

    仔细想想地位卑贱的类型转换功能(cast),其在程序设计中的地位就象goto语句一样令人鄙视.但是它还不是无法令人忍受,因为当在某些紧要的关头,类型转换还是必需的,这时它是一个必需品. 不过C风格的类 ...

  7. Oracle 语句常见错误

    Merge into的注意点之ORA-30926:无法在源表中获得一组稳定的行? merge into 的内部处理是将table_source 的每一条记录和table_target的每一条记录对比匹 ...

  8. mina学习(一)

    Mina:是一个帮助用户开发高性能和高伸缩性网络应用程序的框架 学习地址链接:http://www.cnblogs.com/xuekyo/archive/2013/03/06/2945826.html ...

  9. 关于Java中文乱码与日期格式

    关于Java中文乱码与日期格式 Java中文乱码的问题其实很普遍了,首先,一般不会在Windows平台下面出现,同时,一般在Tomcat应用服务器下也都正常,但是到了WebSphere,Weblogi ...

  10. svn解锁

    SVN解锁操作 现在很多项目开发都使用SVN作为馆控工具,SVN馆中的文件既可以以文件夹的方式获取,也可以通过eclipse导入.获取文件后,我们可以对某个文件锁定. 如果某个同事锁定了某个文件,而他 ...