Everything works fine, but not data retreiving with vlc.net.recv()
Code: Select all
function descriptor()
return { title = "Net Test" }
end
function activate()
-- 1. Variable from webpage to fetch
host = "www.google.fr"
port = 80
path = '/'
-- 2. connect
local tcp = vlc.net.connect_tcp(host, port)
if not tcp then
vlc.msg.dbg('connexion to '..host..':'..port..' : Fail !')
return nil
end
vlc.msg.dbg('connexion to '..host..':'..port..' : OK !')
-- 3. Send GET request
local http_request = "GET "..path.." HTTP/1.1\r\n"..
"Host: "..host.."\r\n"..
"\r\n"
local count = vlc.net.send(tcp, http_request)
vlc.msg.dbg('-> http_request sent : '..http_request)
vlc.msg.dbg('-> '..count..' bytes sent !') -- > 0, it works !
-- => send works, I've tried on my local apache test server, I've got a 200 response ! access.log : "GET / HTTP/1.1" 200 222"
-- 4. Receiving... -_-''
local buffer = ""
local chunk = vlc.net.recv(tcp, 1024)
if not chunk then
vlc.msg.dbg('error -> chunk nil !')
return nil
else
vlc.msg.dbg('error -> chunk OK !')
end
while chunk do
chunk = vlc.net.recv(tcp, 1024)
buffer = buffer..chunk
vlc.msg.dbg('recv !')
-- it never enters this loop.... since chunk is nil....
end
return true
end
function deactivate()
return true
end
qt debug: activating or triggering extension 'Net Test'
lua debug: Activating extension 'Net Test'
main debug: net: connecting to www.google.fr port 80
main debug: connection succeeded (socket = 1952)
lua debug: connexion to www.google.fr:80 : OK !
lua debug: -> http_request sent : GET / HTTP/1.1 Host: www.google.fr
lua debug: -> 39 bytes sent !
lua debug: error -> chunk nil !
I'm using VLC 3.0.12 x64 on Windows 10 x64.
vlc.net.recv(tcp, 1024) returns nil !
I normaly can't use vlc.net.POLLIN because in the README.TXT :
net.poll( { fd = events } ): Implement poll function.
Returns the numbers of file descriptors with a non 0 revent. The function
modifies the input table to { fd = revents }. See "man poll". This function
is not available on Windows.
How can I do for retrieving the result string ???
Thx !