Hello,
For the past few days i’ve been stuck on breaking down firebase database streaming api and trying to reverse engineer the network.request (specifically for download) based on this example git
https://github.com/vsergeyev/corona-firebase/blob/master/corona_firebase.lua
From that example, though it works, I would not want to loop through the temporary file created… and corona’s api does not output any sort of response data in “progress” when I print/print_r’ed it…
So, I figured if it is possible to use a streaming api with corona’s network.request/download, I could, correct me if i’m wrong, get the response while before it it written to the temp file is somewhere in LUA that Corona’s api isn’t spitting out. The problem is I haven’t found the right protocol to use.
Here are some excerpts i’ve tried but does not work.
i’ve tried this but doesn’t work
local connection = http.request({ url = url, sink = ltn12.sink.table(response), redirect = false, headers = { ["accept"] = "text/event-stream", ["content-type"] = "text/event-stream", ["cache-control"] = "no-cache", ["connection"] = "keep-alive" }, })
i’ve also tried this but it just throws off closed
local connection = socket.protect(function(event) local client = socket.try(socket.connect(url, 443)) local try = socket.newtry(function(event) Runtime:removeEventListener("enterFrame", enterFrame) client:close() end) try(client:setoption("tcp-nodelay", true)) try(client:setoption("keepalive", true)) local source = try(socket.source("until-closed", client)) local function enterFrame() local input,output = socket.select({ client }, nil, 0) print(input, output) end Runtime:addEventListener("enterFrame", enterFrame)
local client = socket.tcp() client:connect(url , 443, 0) client:setoption("tcp-nodelay", true) client:settimeout(0) client:setoption("keepalive", true) local input,output = socket.select({ client }, nil, 0) timer.performWithDelay( 200, function() local input,output = socket.select({ client }, nil, 0) for i,v in ipairs(input) do local got\_something\_new = false while true do local skt, e, p = v:receive(1) if (skt) then buffer = buffer.. skt got\_something\_new = true end if (p) then buffer = buffer..p got\_something\_new = true end if (not skt or e) then break end end -- /while-do end end, 0)