Block callback async
Posted: Sun Nov 30, 2014 9:03 am
I'm new to LUA so this is giving me grief
sk=net.createConnection(net.TCP, 0)
sk:dns("www.bbc.co.uk",function(conn,ip) print(ip) end)
sk = nil
That's all very nice- it returns the IP address.. lovely... except that on it's own it's useless. I want to be creating a connection to go get something from a webserver...
Let's say I had a web page (public) from which I wanted to return data...
The ideal function would be returnstring=GetFromWebsite("www.bbc.co.uk", 80)
ie return the text that comes from the BBC website home page - ok - I know that's WAY TOO MUCH - but I have for example a web page that returns a small amount of JSON. I don't want to put the IP address in - for many websites that's unpredictable.
So when creating the connection, I need to use this DNS function to turn the website address into an IP address which is then used in the rest of the code.
Anyone any ideas how to put that first bit of code into a function that is blocking and simply returns the IP address (or an error msg) ??
Pete.
sk=net.createConnection(net.TCP, 0)
sk:dns("www.bbc.co.uk",function(conn,ip) print(ip) end)
sk = nil
That's all very nice- it returns the IP address.. lovely... except that on it's own it's useless. I want to be creating a connection to go get something from a webserver...
Let's say I had a web page (public) from which I wanted to return data...
The ideal function would be returnstring=GetFromWebsite("www.bbc.co.uk", 80)
ie return the text that comes from the BBC website home page - ok - I know that's WAY TOO MUCH - but I have for example a web page that returns a small amount of JSON. I don't want to put the IP address in - for many websites that's unpredictable.
So when creating the connection, I need to use this DNS function to turn the website address into an IP address which is then used in the rest of the code.
Anyone any ideas how to put that first bit of code into a function that is blocking and simply returns the IP address (or an error msg) ??
Pete.