mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 11:03:12 +00:00
28 lines
580 B
Lua
28 lines
580 B
Lua
local skynet = require "skynet"
|
|
local socket = require "socket"
|
|
|
|
local function accepter(id)
|
|
socket.start(id)
|
|
socket.write(id, "Hello Skynet\n")
|
|
while true do
|
|
local str = socket.readline(id,"\n")
|
|
if str then
|
|
socket.write(id, str .. "\n")
|
|
else
|
|
socket.close(id)
|
|
print("closed " .. id)
|
|
return
|
|
end
|
|
end
|
|
end
|
|
|
|
skynet.start(function()
|
|
local id = socket.listen("127.0.0.1", 8000)
|
|
|
|
socket.start(id , function(id, addr)
|
|
print("connect from " .. addr .. " " .. id)
|
|
-- you can also call skynet.newservice for this socket id
|
|
skynet.fork(accepter, id)
|
|
end)
|
|
end)
|