Lua xavante WEB Server implements XMLRPC server-side

Source: Internet
Author: User
Tags lua

Xavante

Xavante is a http1.1-compliant Web server that is implemented using LUA and supports WSAPI.

Dependent libraries:

Xavante Core-Lua, Copas (pure LUA authoring, network connection Coroutine processing), Luasocket processing network connections.

Xavante file Handler--Luafilesystem

This project belongs to a sub-project of the Kepler project, see the official website address:

Http://keplerproject.github.io/xavante/manual.html

Maintain open source code on GitHub:

Https://github.com/keplerproject/xavante

The Xavante provides three types of processing interfaces:

URL mappings, file uploads, and Cgilua calls, configuration run steps see the official website introduction:

Http://keplerproject.github.io/xavante/manual.html#install

Xavante is present in the form of a library and must be downloaded if you want to run WSAPI.

WSAPI

WSAPI is a Web server interface abstracted from a Web application, and a Web application programmed by the Wsapi interface is portable.

Can be run on a different server, including CGI FASTCGI Xavante

Main responsibility, request processing and output cache, see official website for details:

Http://keplerproject.github.io/wsapi/index.html

Installation run:

Http://keplerproject.github.io/wsapi/manual.html

Interface Description Document:

Http://keplerproject.github.io/wsapi/libraries.html

Experiment--LUA XML RPC accesses the XMLRPC service provided by Xavante
    • Download install LUA for Windows

Lua for Windows is an installation package that contains a lot of LUA libraries.

including Luaexpat Luasocket Luafilesystem Copas Rings and other libraries,

Where Copas is the Xavante dependent library;

Luaexpat and Luasocket are lua-xmlrpc dependent libraries.

Http://code.google.com/p/luaforwindows/downloads/list

    • Xavante installation
    • Drag the Xavante directory of SRC in the extracted Xavante folder to the Lua.exe sibling,
    • And the Xavante.lua in the folder are dragged out of the lua.exe sibling.
    • WSAPI Installation
    • Drag the src Wsapi directory and Wsapi.lua file in the Pressurized Wsapi folder to the Lua.exe sibling.
    • Put the LUA-XMLRPC-pressurized src file into the Xmlrpc directory (same as Lua.exe)
    • Add the Lua-xmlrpc Client.lua and Server-xavante.lua to the Lua.exe sibling by adding the add-addition RPC call.

Code:

Client.lua

  • require("xmlrpc.http")--Hello_worldLocalOK, 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 numberLocalOK, 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 EnvironmentfunctionWsapi_handler (wsapi_env)Localheaders = {["Content-type"] ="Text/xml" }   Localreq =wsapi.request.new (wsapi_env)Localmethod, arg_table =Xmlrpc.srvdecode (req. Post.post_data)LocalFunc =Xmlrpc.dispatch (method)Localresult = {Pcall(Func,Unpack(arg_tableor {})) }   LocalOK = result[1]   if  notOk Thenresult= {Code =3, message = result[2] }   Else      Table.remove(Result,1)      ifTABLE.GETN (Result) = =1  Thenresult= result[1]      End   End   LocalR = Xmlrpc.srvencode (result, notOK) headers["Content-length"] =ToString(#R)Local functionxmlrpc_reply (wsapienv)Coroutine.yield(R)End   return  $, headers,Coroutine.wrap(xmlrpc_reply)End--XML-RPC Exported FunctionsXmlrpc_exports = {}---Get simple string.--@return Simple StringfunctionXmlrpc_exports.hello_world ()return "Hello World"End---Add the number function.--@return SumfunctionXmlrpc_exports.add (A, b)returnA +bEndLocalRules = {{match =".", with =Wsapi.xavante.makeHandler (Wsapi_handler)}} LocalConfig = {Server = {host ="*", Port =12345}, Defaulthost = {rules =Rules}} Xmlrpc.srvmethods (xmlrpc_exports) Xavante. HTTP (config) xavante.start ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.