mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
new socket lib
This commit is contained in:
22
service/testsocket.lua
Normal file
22
service/testsocket.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
local skynet = require "skynet"
|
||||
local socket = require "socket"
|
||||
|
||||
local function accepter(id, addr)
|
||||
print("connect from " .. addr .. " " .. id)
|
||||
socket.accept(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()
|
||||
socket.listen("127.0.0.1", 8000, accepter)
|
||||
end)
|
||||
Reference in New Issue
Block a user