-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de312bf
commit 950973d
Showing
7 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./skynet/3rd/lua/lua test/client.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
root="." | ||
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" | ||
luaservice = "./service/?.lua;./skynet/service/?.lua" | ||
lualoader = "./skynet/lualib/loader.lua" | ||
lua_path = "./skynet/lualib/?.lua;./skynet/lualib/?/init.lua" | ||
lua_cpath = "./luaclib/?.so;./skynet/luaclib/?.so" | ||
cpath = "./skynet/cservice/?.so" | ||
-- daemon = "./skynet.pid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
./skynet/skynet config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local skynet = require "skynet" | ||
local netpack = require "netpack" | ||
local socket = require "socket" | ||
local sproto = require "sproto" | ||
local sprotoloader = require "sprotoloader" | ||
|
||
local WATCHDOG | ||
local send_request | ||
|
||
local CMD = {} | ||
local REQUEST = {} | ||
local client_fd | ||
|
||
local function send_package(pack) | ||
local package = string.pack(">s2", pack) | ||
socket.write(client_fd, package) | ||
end | ||
|
||
skynet.register_protocol { | ||
name = "client", | ||
id = skynet.PTYPE_CLIENT, | ||
unpack = function (msg, sz) | ||
return "data", netpack.tostring(msg, sz) | ||
end, | ||
dispatch = function (_, _, type, str) | ||
print(type, str) | ||
end | ||
} | ||
|
||
function CMD.start(conf) | ||
local fd = conf.client | ||
local gate = conf.gate | ||
WATCHDOG = conf.watchdog | ||
client_fd = fd | ||
skynet.call(gate, "lua", "forward", fd) | ||
end | ||
|
||
function CMD.disconnect() | ||
skynet.exit() | ||
end | ||
|
||
skynet.start(function() | ||
skynet.dispatch("lua", function(_,_, command, ...) | ||
local f = CMD[command] | ||
skynet.ret(skynet.pack(f(...))) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
local skynet = require "skynet" | ||
|
||
local max_client = 64 | ||
|
||
skynet.start(function() | ||
skynet.error("Server start") | ||
if not skynet.getenv "daemon" then | ||
local console = skynet.newservice("console") | ||
end | ||
skynet.newservice("debug_console",8000) | ||
local watchdog = skynet.newservice("watchdog") | ||
skynet.call(watchdog, "lua", "start", { | ||
port = 8888, | ||
maxclient = max_client, | ||
nodelay = true, | ||
}) | ||
skynet.error("Watchdog listen on", 8888) | ||
skynet.exit() | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local skynet = require "skynet" | ||
local netpack = require "netpack" | ||
|
||
local CMD = {} | ||
local SOCKET = {} | ||
local gate | ||
local agent = {} | ||
|
||
function SOCKET.open(fd, addr) | ||
skynet.error("New client from : " .. addr) | ||
agent[fd] = skynet.newservice("agent") | ||
skynet.call(agent[fd], "lua", "start", { gate = gate, client = fd, watchdog = skynet.self() }) | ||
end | ||
|
||
local function close_agent(fd) | ||
local a = agent[fd] | ||
agent[fd] = nil | ||
if a then | ||
skynet.call(gate, "lua", "kick", fd) | ||
-- disconnect never return | ||
skynet.send(a, "lua", "disconnect") | ||
end | ||
end | ||
|
||
function SOCKET.close(fd) | ||
print("socket close",fd) | ||
close_agent(fd) | ||
end | ||
|
||
function SOCKET.error(fd, msg) | ||
print("socket error",fd, msg) | ||
close_agent(fd) | ||
end | ||
|
||
function SOCKET.warning(fd, size) | ||
-- size K bytes havn't send out in fd | ||
print("socket warning", fd, size) | ||
end | ||
|
||
function SOCKET.data(fd, msg) | ||
end | ||
|
||
function CMD.start(conf) | ||
skynet.call(gate, "lua", "open" , conf) | ||
end | ||
|
||
function CMD.close(fd) | ||
close_agent(fd) | ||
end | ||
|
||
skynet.start(function() | ||
skynet.dispatch("lua", function(session, source, cmd, subcmd, ...) | ||
if cmd == "socket" then | ||
local f = SOCKET[subcmd] | ||
f(...) | ||
-- socket api don't need return | ||
else | ||
local f = assert(CMD[cmd]) | ||
skynet.ret(skynet.pack(f(subcmd, ...))) | ||
end | ||
end) | ||
|
||
gate = skynet.newservice("gate") | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package.cpath = "./skynet/luaclib/?.so" | ||
package.path = "./skynet/lualib/?.lua" | ||
|
||
|
||
local socket = require "clientsocket" | ||
|
||
local fd = assert(socket.connect("127.0.0.1", 8888)) | ||
|
||
local function send(data) | ||
local package = string.pack(">s2",data) | ||
socket.send(fd, package) | ||
end | ||
|
||
send("hello") | ||
socket.close(fd) |