snax : a simple skynet auxliliary framework

This commit is contained in:
Cloud Wu
2014-04-16 20:12:17 +08:00
parent a420fe498f
commit df5c619a29
6 changed files with 235 additions and 22 deletions

View File

@@ -1,27 +1,23 @@
local skynet = require "skynet"
local command = {}
function command.PING(hello)
function response.ping(hello)
skynet.sleep(100)
return hello
end
function command.HELLO()
skynet.sleep(100)
return "hello"
function subscribe.hello()
print "hello"
end
function command.EXIT()
skynet.exit()
end
function command.ERROR()
function response.error()
error "throw an error"
end
function init( ... )
print ("ping server start:", ...)
end
skynet.start(function()
skynet.dispatch("lua", function(session,addr, cmd, ...)
skynet.ret(skynet.pack(command[cmd](...)))
end)
end)
function exit(...)
print ("ping server exit:", ...)
return "Exit"
end

View File

@@ -1,10 +1,11 @@
local skynet = require "skynet"
local snax = require "snax"
skynet.start(function()
local ps = skynet.uniqueservice("pingserver")
skynet.watch(ps)
print(pcall(skynet.call,ps,"lua","ERROR"))
print(skynet.call(ps, "lua", "PING", "hello"))
print(skynet.call(ps, "lua", "PING", "hay"))
skynet.call(ps, "lua", "EXIT")
local ps = snax.newservice ("pingserver", "hello world")
print(ps.pub.hello())
print(ps.req.ping("foobar"))
print(pcall(ps.req.error))
print(ps.kill("exit"))
skynet.exit()
end)