As the title says... Chat on...

User avatar
By xykon
#3643 I tried this:

Code: Select allfunction getip(host)
  ip=nil
  c=net.createConnection(net.TCP, false)
  c:dns(host, function(conn,addr) ip=addr end)
  while ip==nil do tmr.delay(500000) tmr.wdclr() end  -- does not work; need to enter event loop manually?
  return ip
end


But it does not work.

Seems like it is busy waiting in tmr.delay() and thus cannot process the answer from the DNS.
Is there a way to get Lua to process all pending events? (In this case the DNS callback)

Sure, I could work around this problem by just putting all my code into the callback, but I think that's kind of ugly. Also, I would not know how to do something like "Lookup example.com but continue with 192.168.1.2 if you don't get an answer after 3 seconds."

Any Ideas?

Xykon
User avatar
By scargill
#3644 I have to say, apart from contacting an internal web, I can't think of any time I would want to contact server via it's ip address. The norm would be to do so via the name.

I'm running into serious memory problems - adding that as a file with just a few other things in there and I run out of memory.
User avatar
By xykon
#3678 Yeah, maybe that was a bad example, but the problem persists. How do I do a dns lookup with a timeout?
Would be easy if there was a node.process_events() or similar. Maybe there is, but I don't know, since I am both a Lua-newbie and a nodemcu-newbie. ;-)