--!movie
--!encoding=utf-8
global $
----------------------------------------
-- Asynchronous or non-blocking mode, using callbacks
----------------------------------------
on startMovie
_player.debugPlaybackEnabled = 1
-- libs
$.import("curl")
--------------------------------------------------
-- Curl connection 1: DOWNLOAD
--------------------------------------------------
_global.ch1 = $.curl.init() -- important for async mode: make CURL handle persistant!
-- specify options
_global.ch1.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/test.mp3")
_global.ch1.setDestinationFile($.PATH & "downloaded.mp3")
-- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
-- A) Use async xtra function directly. Drawback: lingo errors in callback code fail silently
-- _global.ch1.execAsync(#slotCurlResult1)
-- B) Use helper function to "detach" callbacks from original thread, so errors are shown and can be debugged!
$.curl.execAsyncDetached(_global.ch1, #slotCurlResult1)
--------------------------------------------------
-- Curl connection 2: GET (ERROR)
--------------------------------------------------
_global.ch2 = $.curl.init() -- important for async mode: make CURL handle persistant!
-- specify options
_global.ch2.setOption($.curl.CURLOPT.URL, "http://doesntexist.xxxrtzr.com/") -- test network error handling
$.curl.execAsyncDetached(_global.ch2, #slotCurlResult2)
--------------------------------------------------
-- Curl connection 3: POST
--------------------------------------------------
_global.ch3 = $.curl.init() -- important for async mode: make CURL handle persistant!
-- specify options
_global.ch3.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/echo.php")
_global.ch3.setOption($.curl.CURLOPT.POSTFIELDS, "foo=äöü&bar=hello%20world")
$.curl.execAsyncDetached(_global.ch3, #slotCurlResult3)
put "CONTINUE LINGO EXECTION..."
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult1 (res)
-- x = 1/0 -- uncomment to check if errors fail silently or not
put
put "--------------------------------------------------"
put " CALLBACK FOR CURL CONNECTION 1"
put "--------------------------------------------------"
if integerP(res) then
put "ERROR:" && curl_error(res)
else
put "RESULT:" && res.readRawString(res.length)
end if
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult2 (res)
put
put "--------------------------------------------------"
put "CALLBACK FOR CURL CONNECTION 2"
put "--------------------------------------------------"
if integerP(res) then
put "ERROR:" && curl_error(res)
else
put "RESULT:" && res.readRawString(res.length)
end if
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult3 (res)
put
put "--------------------------------------------------"
put "CALLBACK FOR CURL CONNECTION 3"
put "--------------------------------------------------"
if integerP(res) then
put "ERROR:" && curl_error(res)
else
put "RESULT:" && res.readRawString(res.length)
end if
end