mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
snax : a simple skynet auxliliary framework
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user