luasocket 支持ipv6

dump(socket.dns.getaddrinfo("ipv6-test.com"))

"" = {
[LUA-print] -     1 = {
[LUA-print] -         "addr"   = "5.135.165.173"
[LUA-print] -         "family" = "inet"
[LUA-print] -     }
[LUA-print] -     2 = {
[LUA-print] -         "addr"   = "2001:41d0:8:e8ad::1"
[LUA-print] -         "family" = "inet6"
[LUA-print] -     }
[LUA-print] - }


local addrifo = socket.dns.getaddrinfo("www.baidu.com")
    if addrifo ~= nil then
        for k,v in pairs(addrifo) do
            if v.family == "inet6" then
                isipv6_only = true
                break
            end
        end
    end

    if isipv6_only then
        self.tcp = socket.tcp6()
    else
        self.tcp = socket.tcp()
    end


你可能感兴趣的:(cocos2d-lua)