Skip to content

Commit 6dc1ca5

Browse files
author
kylemao
committed
init
0 parents  commit 6dc1ca5

10 files changed

+603
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/run
2+
/cservice

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "skynet"]
2+
path = skynet
3+
url = https://github.com/cloudwu/skynet.git

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
这是一个使用 skynet 搭建服务器的简单例子。它很简陋,主要想演示一下 https://github.com/cloudwu/skynet_package 以及 sproto 协议封装的用法。
2+
3+
这个例子可以作为构建游戏服务器的参考,但它并不作为 skynet 推荐的服务器框架使用模式。它还很不完整,可能存在许多疏忽的地方,以及需要针对实际需求做进一步优化。
4+
5+
如何编译
6+
========
7+
8+
1. clone 下本仓库。
9+
2. 更新 submodule ,服务器部分需要用到 skynet ;客户端部分需要用到 lsocket 。
10+
```
11+
git submodule update --init
12+
```
13+
3. 编译 skynet
14+
```
15+
cd skynet
16+
make linux
17+
```
18+
4. 编译 lsocket(如果你需要客户端)
19+
```
20+
make socket
21+
```
22+
5. 编译 skynet package 模块
23+
```
24+
make
25+
```
26+
27+
如何运行服务器
28+
==============
29+
30+
以前台模式启动
31+
```
32+
./run.sh
33+
```
34+
用 Ctrl-C 可以退出
35+
36+
以后台模式启动
37+
```
38+
./run.sh -D
39+
```
40+
41+
用下列指令可以杀掉后台进程
42+
```
43+
./run.sh -k
44+
```
45+
46+
后台模式下,log 记录在 `run/skynet.log` 中。
47+
48+
49+
50+

config

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = "$ROOT/"
2+
thread = 8
3+
logpath = root .. "run"
4+
harbor = 0
5+
--start = "main" -- main script
6+
start = "ws_master" -- 入口服务
7+
luaservice = root .. "service/?.lua;" .. root .."skynet/service/?.lua"
8+
lualoader = root .. "skynet/lualib/loader.lua"
9+
lua_path = root .. "lualib/?.lua;" .. root .. "skynet/lualib/?.lua;" .. root .. "skynet/lualib/?/init.lua"
10+
lua_cpath = root .. "skynet/luaclib/?.so"
11+
cpath = root .. "/cservice/?.so;"..root.."/skynet/cservice/?.so"
12+
13+
-- WebSocket配置
14+
ws_worker_num = 4 -- 工作线程数
15+
ws_port = 8081 -- 监听端口(需与前端保持一致)
16+
17+
if $DAEMON then
18+
logger = root .. "run/skynet.log"
19+
daemon = root .. "run/skynet.pid"
20+
end
21+

lualib/log.lua

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local skynet = require "skynet"
2+
3+
local log = {}
4+
5+
function log.format(fmt, ...)
6+
skynet.error(string.format(fmt, ...))
7+
end
8+
9+
function log.__call(self, ...)
10+
if select("#", ...) == 1 then
11+
skynet.error(tostring((...)))
12+
else
13+
self.format(...)
14+
end
15+
end
16+
17+
return setmetatable(log, log)

0 commit comments

Comments
 (0)