在examples同一级目录新建目录myexample,该目录下面新建以下几个文件:
myexample/config,内容:
?
root = "./"
luaservice = root.."service/?.lua;"..root.."myexample/eg1/?.lua"
lualoader = root .. "lualib/loader.lua"
lua_path = root.."lualib/?.lua;"..root.."lualib/?/init.lua"
lua_cpath = root .. "luaclib/?.so"
snax = root.."examples/?.lua;"..root.."test/?.lua"
?
-- preload = "./examples/preload.lua" ??-- run preload.lua before every lua service run
thread = 8
logger = nil
logpath = "."
harbor = 1
address = "127.0.0.1:2526"
master = "127.0.0.1:2013"
start = "main" ?-- main script
bootstrap = "snlua bootstrap" ??-- The service for bootstrap
standalone = "0.0.0.0:2013"
-- snax_interface_g = "snax_g"
cpath = root.."cservice/?.so"
-- daemon = "./skynet.pid"
?
proto.lua是定义通信协议,代码:
local sprotoparser =require"sprotoparser"
local proto ={}
proto.c2s = sprotoparser.parse [[
.package {
???type 0 : integer
???session 1 : integer
}
handshake 1 {
???response {
???????msg 0 ?: string
???}
}
say 2 {
???request {
???????name 0 : string
???????msg 1 : string
???}
}
quit 3 {}
]]
proto.s2c = sprotoparser.parse [[
.package {
???type 0 : integer
???session 1 : integer
}
heartbeat 1 {}
]]
return proto
Skynet入门范例之sproto
原文地址:http://www.cnblogs.com/skiing886/p/7694813.html