mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
If recv one udp message, try read next immediately rather than until next epoll_wait
This commit is contained in:
@@ -4,8 +4,9 @@ local socket = require "socket"
|
||||
local function server()
|
||||
local host
|
||||
host = socket.udp(function(data, sz, from)
|
||||
print("server recv", skynet.tostring(data,sz), socket.udp_address(from))
|
||||
socket.sendto(host, from, "OK")
|
||||
local str = skynet.tostring(data,sz) -- skynet.tostring should call only once, because it will free the pointer data
|
||||
print("server recv", str, socket.udp_address(from))
|
||||
socket.sendto(host, from, "OK " .. str)
|
||||
end , "127.0.0.1", 8765) -- bind an address
|
||||
end
|
||||
|
||||
@@ -14,7 +15,9 @@ local function client()
|
||||
print("client recv", skynet.tostring(data,sz), socket.udp_address(from))
|
||||
end)
|
||||
socket.udp_connect(c, "127.0.0.1", 8765)
|
||||
socket.write(c, "hello") -- write to the address by udp_connect binding
|
||||
for i=1,20 do
|
||||
socket.write(c, "hello " .. i) -- write to the address by udp_connect binding
|
||||
end
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
|
||||
Reference in New Issue
Block a user