vlc.net.recv() not working !!

Discuss your Lua playlist, album art and interface scripts.
spark90
Blank Cone
Blank Cone
Posts: 23
Joined: 31 Mar 2021 03:00

vlc.net.recv() not working !!

Postby spark90 » 08 Apr 2021 00:45

Here is my extension, I want to get the html index code from www.google.fr :
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
And the logfile :
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 ! :evil:


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 !

spark90
Blank Cone
Blank Cone
Posts: 23
Joined: 31 Mar 2021 03:00

Re: vlc.net.recv() not working !!

Postby spark90 » 08 Apr 2021 00:54

OK...... The documentation is not up to date...

vlc.net.poll is available for windows !

I tried

Code: Select all

-- 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" local pollfds = {} pollfds[tcp] = vlc.net.POLLIN vlc.net.poll(pollfds)
=> résult log :
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 = 1960)
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 OK !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua debug: recv !
lua warning: Error while running script C:\Users\Spark\AppData\Roaming\vlc\lua\extensions\net.lua, function activate(): ...ers\Spark\AppData\Roaming\vlc\lua\extensions\net.lua:52: attempt to concatenate local 'chunk' (a nil value)
lua error: Could not activate extension!
lua debug: Deactivating 'Net Test'
just need to modify some stuffs and il will works perfectly :D


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 9 guests