simple and easy socket support for lua
To build windows version, use make mingw
lsocket from http://tset.de/lsocket/
simple and easy socket support for lua
To build windows version, use make mingw
在 ca6e1d8 这次提交后,发现 win_compat.h 内容居然和 win_compat.c 文件内容一毛一样了。应该是提交错了吧。
系统:Windows 10
平台:msys2
执行 lsocket.connect(ip, port)
传入的 ip 的地址格式正确,但指向一个不存在的主机。就想测试下这种情况,发现 lsocket.connect
返回的第二个参数是空串,定位是下面这行代码返回的:
Line 419 in 8e7752c
Windows 系统真的神奇,就期望着如果传入了不存在的主机,lsocket.connect
的第二个参数能不能返回相应的字符串描述。不过目前倒也不影响使用。
-------------------------------代码-------------------------------
local lsocket = require("lsocket")
function split(str,reps)
if string.find(str,reps) ~= nil then
local resultStrList = {}
string.gsub(str,'[^'..reps..']+',function (w)
table.insert(resultStrList,w)
end)
return resultStrList
else return nil
end
end
server ="8.8.8.8"
port = 53
host = "baidu"
local client, err = lsocket.connect("tcp",server,port)
if not client then
print("error: "..err)
return nil
end
math.randomseed(os.time())
local data = string.char(math.random(1,255),math.random(1,255))
data = data .. string.char(0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00)
local temp = split(host,".")
for i,v in pairs(temp) do
data = data .. string.char(string.len(v))
for j=1,string.len(v) do
data = data .. string.sub(v,j,j)
end
end
data = data .. string.char(0x00,0x00,0x01,0x00,0x01)
data = string.char(0x00,string.len(data)) .. data
ok, err = client:send(data)
if not ok then print("error: "..err) end
-------------------------------代码-------------------------------
最近在学习写dns查询的测试代码,当在windows下执行时,tcp模式下send,会出现"error: Unknown error"错误,但是同样的代码在linux环境下执行时,会正常运行,不知道是我编译的问题,还是库的问题,希望能指导解决
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.