Skip to content

Instantly share code, notes, and snippets.

@cloudwu
Last active August 29, 2015 14:01
Show Gist options
  • Save cloudwu/d36e313dab322917634f to your computer and use it in GitHub Desktop.
Save cloudwu/d36e313dab322917634f to your computer and use it in GitHub Desktop.
local skynet = require "skynet"
local socket = require "socket"
local mode = ...
if mode == "agent" then
skynet.start(function()
skynet.dispatch("lua", function(_,_,id)
socket.start(id)
socket.readline(id, "\r\n\r\n")
socket.write(id, "HTTP/1.1 200 ok\r\nContent-Length: 1\r\n\r\n1")
socket.close(id)
end)
end)
else
local agent = {}
local N = 10
skynet.start(function()
for i = 1, N do
local handle = skynet.newservice("simpleweb", "agent")
table.insert(agent, handle)
end
local id = socket.listen("127.0.0.1", 8001)
print("Listen socket :", "127.0.0.1", 8001)
local idx = 1
socket.start(id , function(id, addr)
skynet.send(agent[idx], "lua", id)
idx = idx + 1
if idx > N then
idx = 1
end
end)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment