在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:distri.lua开源软件地址:https://gitee.com/sniperHW/distri.lua开源软件介绍:distri.luadistri.lua is a lua concurrency networking framework aid to help the developer to fastbuild online game server ,web application,light distributed system and so on. Features include:
distri.lua is licensed under GPL license. get distri.luaInstall libcurl Install lua 5.2. Clone the repository. Post feedback and issues on the bug tracker, buildin Ubuntusudo apt-get install libssl-devsudo apt-get install libreadline-devmakein FreeBSDgmake running testspingpong test./distrilua samples/hello.lua./distrilua samples/pingclient.luarpc test./distrilua samples/rpcserver.lua./distrilua samples/rpcclient.lua to-do list
http testlocal Http = require "lua/http"Http.CreateServer(function (req, res) res:WriteHead(200,"OK", {"Content-Type: text/plain"}) res:End("Hello World\n"); end):Listen("127.0.0.1",8001)print("create server on 127.0.0.1 8001") udp testserver local Socket = require "lua.socket"local Timer = require "lua.timer"local Sche = require "lua.sche"local count = 0local s = Socket.Datagram.New(CSocket.AF_INET,1024,Socket.Datagram.RDecoder())s:Listen("127.0.0.1",8010)Sche.Spawn(function () while true do local rpk,from = s:Recv() --print(from[1],from[2],from[3]) count = count + 1 s:Send(Socket.WPacket(rpk),from) endend)local last = C.GetSysTick()local timer = Timer.New():Register(function () local now = C.GetSysTick() print(string.format("count:%d",count*1000/(now-last))) count = 0 last = nowend,1000):Run() client local Socket = require "lua.socket"local s = Socket.Datagram.New(CSocket.AF_INET,1024,Socket.Datagram.RDecoder())for i = 1,3 do local wpk = Socket.WPacket(1024) wpk:Write_string("hello") s:Send(wpk,{CSocket.AF_INET,"127.0.0.1",8010})endwhile true do local rpk,from = s:Recv() s:Send(Socket.WPacket(rpk),from)end RPC testserver local TcpServer = require "lua.tcpserver"local App = require "lua.application"local RPC = require "lua.rpc"local Timer = require "lua.timer"local Sche = require "lua.sche"local Socket = require "lua.socket"local count = 0local rpcserver = App.New()rpcserver:RPCService("Plus",function (_,a,b) count = count + 1 return a+b end)local successlocal success = not TcpServer.Listen("127.0.0.1",8000,function (client) print("on new client") rpcserver:Add(client:Establish(Socket.Stream.RDecoder())) end)if success then print("server start on 127.0.0.1:8000") local last = C.GetSysTick() local timer = Timer.New():Register(function () local now = C.GetSysTick() print(string.format("cocount:%d,rpccount:%d,elapse:%d", Sche.GetCoCount(),count*1000/(now-last),now-last)) count = 0 last = now end,1000):Run()else print("server start error")end client local Socket = require "lua.socket"local App = require "lua.application"local RPC = require "lua.rpc"local Sche = require "lua.sche"local rpcclient = App.New()for i=1,10 do Sche.Spawn(function () local client = Socket.Stream.New(CSocket.AF_INET) if client:Connect("127.0.0.1",8000) then print("connect to 127.0.0.1:8000 error") return end rpcclient:Add(client:Establish(Socket.Stream.RDecoder()),nil,on_disconnected) local rpcHandler = RPC.MakeRPC(client,"Plus") for j=1,100 do Sche.Spawn(function (client) while true do local err,ret = rpcHandler:Call(1,2) if err then print("rpc error:" .. err) client:Close() return end end end,client) end end) end test redis clientlocal Redis = require "lua.redis"local Sche = require "lua.sche"local Timer = require "lua.timer"local count = 0local toredislocal function connect_to_redis() print("here") if toredis then print("to redis disconnected") end toredis = nil Sche.Spawn(function () while true do local err err,toredis = Redis.Connect("127.0.0.1",6379,connect_to_redis) if toredis then break end print("try to connect after 1 sec") Sche.Sleep(1000) end end) endconnect_to_redis()while not toredis do Sche.Yield()endlocal err,result = toredis:CommandSync("hmget test nickname")if result then for k,v in pairs(result) do print(k,v) endend demo of online gamesee Survive |
请发表评论