mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
rewrite example testping
This commit is contained in:
@@ -3,12 +3,12 @@ local skynet = require "skynet"
|
|||||||
local command = {}
|
local command = {}
|
||||||
|
|
||||||
function command.PING(hello)
|
function command.PING(hello)
|
||||||
skynet.ret(skynet.pack(hello))
|
return hello
|
||||||
end
|
end
|
||||||
|
|
||||||
function command.HELLO()
|
function command.HELLO()
|
||||||
skynet.sleep(100)
|
skynet.sleep(100)
|
||||||
skynet.ret(skynet.pack("hello"))
|
return "hello"
|
||||||
end
|
end
|
||||||
|
|
||||||
function command.EXIT()
|
function command.EXIT()
|
||||||
@@ -19,8 +19,9 @@ function command.ERROR()
|
|||||||
error "throw an error"
|
error "throw an error"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
skynet.dispatch("lua", function(session,addr, cmd, ...)
|
skynet.dispatch("lua", function(session,addr, cmd, ...)
|
||||||
command[cmd](...)
|
skynet.ret(skynet.pack(command[cmd](...)))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ local skynet = require "skynet"
|
|||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local ps = skynet.uniqueservice("pingserver")
|
local ps = skynet.uniqueservice("pingserver")
|
||||||
skynet.watch(ps)
|
skynet.watch(ps)
|
||||||
-- print(pcall(skynet.call,ps,"lua","ERROR"))
|
print(pcall(skynet.call,ps,"lua","ERROR"))
|
||||||
print(skynet.call(ps, "lua", "PING", "hello"))
|
print(skynet.call(ps, "lua", "PING", "hello"))
|
||||||
print(skynet.call(ps, "lua", "PING", "hay"))
|
print(skynet.call(ps, "lua", "PING", "hay"))
|
||||||
skynet.send(ps, "lua", "EXIT")
|
skynet.call(ps, "lua", "EXIT")
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user