functionnstol(str) assert(str and #str == 4) local t = {str:byte(1,-1)} local n = 0 for k = 1, #t do n= n*256 + t[k] end return n end
-- get time from a ip address, use tcp protocl functiongettime(ip) print('connect ', ip) local tcp = socket.tcp() tcp:settimeout(10) tcp:connect(ip, 37) success, time = pcall(nstol, tcp:receive(4)) tcp:close() return success andtimeornil end
functionnettime() for _, ip inpairs(server_ip) do time = gettime(ip) iftimethen returntime end end end
no field package.preload['socket']
no file '.\socket.lua'
no file 'F:\Projects\Lua\nettime\lua\socket.lua'
no file 'F:\Projects\Lua\nettime\lua\socket\init.lua'
no file 'F:\Projects\Lua\nettime\socket.lua'
no file 'F:\Projects\Lua\nettime\socket\init.lua'
no file 'D:\tools\Lua\5.1\lua\socket.luac'
no file '.\socket.dll'
no file '.\socket51.dll'
no file 'F:\Projects\Lua\nettime\socket.dll'
no file 'F:\Projects\Lua\nettime\socket51.dll'
no file 'F:\Projects\Lua\nettime\clibs\socket.dll'
no file 'F:\Projects\Lua\nettime\clibs\socket51.dll'
no file 'F:\Projects\Lua\nettime\loadall.dll'
no file 'F:\Projects\Lua\nettime\clibs\loadall.dll'.
网上也有好多类似的提问,大抵是没仔细看作者的Guide。显著的有这么一句
The other two environment variables instruct the compatibility module to look for dynamic libraries and extension modules in the appropriate directories and with the appropriate filename extensions.>