So, this works:
<snippet>:
who = "www.google.com"
net.dns.resolve(who, function(sk, ip)
if (ip ~= nil)
then uart.write(0,ip)
else uart.write(0,"host not found")
end
end)
However, I cannot make it work when I assign a part of a string to the variable "who", so replacing
who = "www.google.com"
with
data = "whois http://www.google.com"
cmd_start,cmd_end = string.find(data,"whois ")
who = string.sub(data,cmd_end+1)
Resulting in the <snippet>:
data = "whois http://www.google.com"
cmd_start,cmd_end = string.find(data,"whois ")
who = string.sub(data,cmd_end+1)
net.dns.resolve(who, function(sk, ip)
if (ip ~= nil)
then uart.write(0,ip)
else uart.write(0,"host not found")
end
end)
... basically removing "whois " from a string "whois http://www.google.com".
As a test I have printed the result of "who" between brackets
print("[" .. who .. "]")
And this shows "[www.google.com]", no spaces. Printing the type of the variable who gives "string", so it seems to be fine. But still it does not work: I keep getting "host not found".
What am I doing wrong? All help appreciated.