1.提供支持ipv6的udp client和server接口, 可支持ipv6 (#1967)

* 1.提供支持ipv6的udp client和server接口, 可支持ipv6

* remove chinese comments
This commit is contained in:
huojicha
2024-08-08 02:34:15 +08:00
committed by GitHub
parent bcf97ecd1b
commit 839570ce3f
7 changed files with 218 additions and 3 deletions

View File

@@ -4,14 +4,14 @@ local socket = require "skynet.socket"
local function server()
local host
host = socket.udp(function(str, from)
print("server recv", str, socket.udp_address(from))
print("server v4 recv", str, socket.udp_address(from))
socket.sendto(host, from, "OK " .. str)
end , "127.0.0.1", 8765) -- bind an address
end
local function client()
local c = socket.udp(function(str, from)
print("client recv", str, socket.udp_address(from))
print("client v4 recv", str, socket.udp_address(from))
end)
socket.udp_connect(c, "127.0.0.1", 8765)
for i=1,20 do
@@ -19,7 +19,30 @@ local function client()
end
end
local function server_v6()
local server
server = socket.udp_listen("::1", 8766, function(str, from)
print(string.format("server_v6 recv str:%s from:%s", str, socket.udp_address(from)))
socket.sendto(server, from, "OK " .. str)
end) -- bind an address
print("create server succeed. "..server)
return server
end
local function client_v6()
local c = socket.udp_dial("::1", 8766, function(str, from)
print(string.format("client recv v6 response str:%s from:%s", str, socket.udp_address(from)))
end)
print("create client succeed. "..c)
for i=1,20 do
socket.write(c, "hello " .. i) -- write to the address by udp_connect binding
end
end
skynet.start(function()
skynet.fork(server)
skynet.fork(client)
skynet.fork(server_v6)
skynet.fork(client_v6)
end)