1. 程式人生 > >Skynet入門範例之sproto

Skynet入門範例之sproto

path one run return lac pac ots before req

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