Fantastic! Thank you, Javier, here is the code I'm working with, it listens on my UDP port and prints registers the events. I'm just trying to bootstrap my way into doing something cool, XBMC integration.
-- Utility functions provided by MCV, here for local testing
function SetUPnPState(variable_name, variable_value)
-- Would in reality register the variables
print("Registered " .. variable_name .. " as " .. variable_value)
end
-- My Script
require "socket"
-- Opens the UDP port
-- Should be trying to receive from the non-forwarding IP 255.255.255.255 but * seems to work
-- Should open the port 8278 which is XBMC's default UDP port
function startup()
udpport = assert (socket.udp())
assert (udpport:setsockname ('*', 8278))
udpport:settimeout (nil) -- wait indefinitely
local message, host = assert (udpport:receivefrom(1024))
--print("Message " .. message)
print("Host " .. host)
incomingData(message)
end
function incomingData(message)
if (string.find(message, "OnPlayBackStarted") ~= nil) then
SetUPnPState("PlaybackStatus", "Playing")
elseif (string.find(message, "OnPlayBackPaused") ~= nil) then
SetUPnPState("PlaybackStatus", "Paused")
else
print("Message " .. message)
end
end
startup()
Something I don't understand is where does the
local message, host = assert (udpport:receivefrom(1024))
go? It doesn't seem to belong in the startup block. I need to wait and receive these message indefinitely and pass the result to the incomingData function. Also what does the incomingData function actually receive? I need to grab the IP address and the message as this device is really the top level device for sub devices.
Thanks for any help or tips.
Sincerely,
Nick