Files
skynet/service/testsocket.lua
2013-08-24 00:14:01 +08:00

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)