determinate determinate

Author Topic: Lua socket.http for a client?  (Read 1505 times)

0 Members and 1 Guest are viewing this topic.

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Lua socket.http for a client?
« on: July 27, 2010, 08:36:25 pm »
Hello everyone,

First of all I want to tell you that I'm a complete newbie in Lua or scripting, so please if you explain to me something, do it like you would explain it to an idiot, LOL. (I can RTFM so I'm not that bad if you point me to the proper direction :P)

I am trying to make a script for BCDC++ and VLC media player, it should retrieve the "127.0.0.1:8080/nowplaying.html" that I have setup already and post it in the chat. But I have problems with setting up the socket library, I have tested PXLuaSocket-2.0.2 that was intended for PtokaX, but I have problems with it, I get errors when I try to use it in my script to connect to the VLC webserver:

[21:34:26]  LUA ERROR: (vlcnp.lua: ownChatOut) C:\Users\[UserName]\Documents\BCDC++\scripts\vlcnp.lua:8: loop or previous error loading module 'socket.http'

I've searched for another compiled one but I can't find. Source does me no good, I have no compiler nor I know how to use one.
So I was wondering if someone could help me with that, here is my script so far:

Code: [Select]
host = "127.0.0.1"
port = ":8080"
file = "/nowplaying.html"

dcpp:setListener( "ownChatOut", "vlcnp",
function ( hub, text )

local http = require("socket.http")

local txt = DC():FromUtf8(text)
local prefix = string.sub(txt, 1, 1)

if prefix == "+" or prefix == "!"  then
return
elseif prefix == "/" then

local cmd = string.sub(txt, 2)
string.lower(cmd)

if  cmd == "vlc" then

np = http.request(host..port..page)

hub:sendChat(np)
return 1
else
return
end

else
msg = txt

end

hub:sendChat(msg)
return 1

end

)

DC():PrintDebug("  ** Loaded vlcnp.lua **")
« Last Edit: July 28, 2010, 12:24:50 am by pzf »

Offline lUk3f1l3w4lK3R

  • Junior Member
  • **
  • Posts: 23
  • Karma: +4/-0
Re: Lua socket.http for a client?
« Reply #1 on: July 27, 2010, 10:02:31 pm »
I dont know if it will help cause i never wrote a client side script but you can get another LUASocket library here:
http://luaforge.net/frs/?group_id=23&release_id=837

cheers

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #2 on: July 27, 2010, 11:31:44 pm »
PXLuaSocket-2.0.2 as the name indicates is for use in PtokaX.
It will not work without errors in your client. The docs in the
Lua Socket 2.0 package are all you need. I noticed you were
trying to pickup on 127.0.0.1:8080/nowplaying.html with
the socket lib. If this [as it seems to be] is a local path
that is accessible by the hub computer, then it would
be best to just read that file with the Lua io lib and
parse the information necessary.
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #3 on: July 28, 2010, 12:36:28 am »
Mutor, if I open it locally I will get "<vlc id="value" param1="'ARTIST' vlc_get_meta"/> - <vlc id="value" param1="'TITLE' vlc_get_meta"/>" not the current file playing. I need to get it through the webserver of VLC.

lUk3f1l3w4lK3R, thanks but I still get that error even with the libraries from that link:

Quote
[01:13:20]  LUA ERROR: (vlcnp.lua: ownChatOut) C:\Users\s3m0\Documents\BCDC++\scripts\vlcnp.lua:8: loop or previous error loading module 'socket.http'

Maybe I'm not putting the files in the proper folder? I was trying in the install folder of BCDC++ and also in the settings folder but still the same problem. If I remove the libraries the error is:

Quote
[01:34:04]  LUA ERROR: (vlcnp.lua: ownChatOut) C:\Users\s3m0\Documents\BCDC++\scripts\vlcnp.lua:8: module 'socket.http' not found:
   no field package.preload['socket.http']
   no file '.\socket\http.lua'
   no file 'C:\Program Files\BCDC++\lua\socket\http.lua'
   no file 'C:\Program Files\BCDC++\lua\socket\http\init.lua'
   no file 'C:\Program Files\BCDC++\socket\http.lua'
   no file 'C:\Program Files\BCDC++\socket\http\init.lua'
   no file '.\socket\http.dll'
   no file 'C:\Program Files\BCDC++\socket\http.dll'
   no file 'C:\Program Files\BCDC++\loadall.dll'
   no file '.\socket.dll'
   no file 'C:\Program Files\BCDC++\socket.dll'
   no file 'C:\Program Files\BCDC++\loadall.dll'

So I think that C:\Program Files\BCDC++\ is the proper folder. This leads me to thinking that the problem is again the library ???
Any suggestions?

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #4 on: July 28, 2010, 12:40:56 am »
The root of your client is the proper place.
You shouldn't call the lib in every ownChatOut
listener. It will try to load the lib every time you
chat. You only need load the socket lib once,
preferably first.
« Last Edit: July 28, 2010, 12:43:25 am by Mutor »
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #5 on: July 28, 2010, 01:04:58 am »
OK I understand, this is what I did firstly and had the same error. Then I had a look at some other scripts that use that lib and changed it for testing, though they were for PtokaX, not a client. I will fix it, but still it doesn't work and it gives me the same error, just on another row. :D

Edit: Anyone ever managed to use the socks lib in a client? :-\
« Last Edit: July 28, 2010, 12:04:59 pm by pzf »

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #6 on: July 31, 2010, 01:33:01 pm »
I gave up on the socks lib, can't get it to work in my client. :'(

Found out that VLC has some Lua support to, but coudn't make it work, it's either bugged like hell or I can't seem to understand it, the documentation sucks. My idea was to write the song in a file and then read it with BCDC++ but to hell with it.

Tried using os.execute() with wget and download the html file, then read it with the script, this works but when I use os.execute() it pops up a cmd window, which is not elegant at all. Did so many things in attempt to hide the cmd window with no succes.  :(

I'm out of ideas now.

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #7 on: July 31, 2010, 01:51:15 pm »
Well you can write a hub side script.
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #8 on: July 31, 2010, 02:00:04 pm »
Yeah, but I don't host the hub, I'm just an admin there and the owner will probably just laugh at me when I tell her that I want the hub to run a script which I could use for my VLC Now Playing feature.  ;D

Oh and I would like to use it in all hubs, so client side is much better for this purpose.  :)
« Last Edit: July 31, 2010, 02:02:36 pm by pzf »

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #9 on: July 31, 2010, 02:39:06 pm »
As I find it's your intent to spam hubs you don't
own, I'm laughing too. Let me guess, another DJ?

Some DC clients already have a plugin interface to
return now playing status from winamp, windows
media player, windows media player classic etc.

Perhaps you can simply annoy others with these.
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #10 on: July 31, 2010, 03:45:56 pm »
In the hubs where I reside most people do that and we do not frown upon it like spam...

I can see that you think in another way, everyone is free to have their own opinion about it, if I ever come along in a hub of your authority feel free to enforce your opinion on me.

I know that clients have option for other players, I just wanted to make one for VLC myself.

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #11 on: July 31, 2010, 04:45:19 pm »
In the hubs where I reside most people do that and we do not frown upon it like spam...

the owner will probably just laugh at me when I tell her that I want the hub to run a script which I could use for my VLC Now Playing feature.  ;D

Well which is it? :P
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #12 on: July 31, 2010, 05:48:05 pm »
The funny thing is using such a script hub side. That is what I meant, not the use of such feature. :)

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: Lua socket.http for a client?
« Reply #13 on: July 31, 2010, 06:51:05 pm »
Well it certainly can be done client side and perhaps should be.
It seems to me you only need HTML Get and not the full socket lib.
To that end you can use [ webGet ]

Quote
A Lua 5.1 module to download files and XML/RDF triples from internet. This module provides also a XML SAX parser to analyse XML dowloaded files. Uses WinInet (allows HTTP/HTTPS/FTP, cookies, a download cache and http proxy).

It loads fine in RSX++ for me and so it should for you in BCDC++
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline pzf

  • Junior Member
  • **
  • Posts: 15
  • Karma: +0/-0
Re: Lua socket.http for a client?
« Reply #14 on: July 31, 2010, 08:35:57 pm »
On my first test it worked like a charm, thanks a lot Mutor. I just need to read the documentation to get the hang of it.  ;D

 

determinate determinate