PDA

View Full Version : How do I account for a computer being offline in socket.http.request?



Mastiff
May 26th, 2016, 05:43 AM
Never mind, found a way:


if http.request("http://192.168.0.15:8080/") == nil
then
print ("Nothing here")
else
print ("Here we are")
end


I have this code to check if JRMC is playing:


local _, _, PlayMode = string.find(socket.http.request('http://192.168.0.15/MCWS/v1/Playback/Info?Zone=' .. SoneVariable .. '&ZoneType=Index'), 'State">(%d+)<')

The problem comes when the computer it checks is offline, or JRMC has exited with an error, or something like that. It doesn't happen often (maybe every third month or so), but I would like to have a check for that, but I get:


bad argument #1 to `find' (string expected, got nil)

So is there any way to check if JRMC is offline and have a new action happen in that cas? I can create the action, so let's just say:


print("JRMC is offline")

And if it's online just continue the script as usual.