PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Help with scripts => Topic started by: Hamachi on 08 February, 2012, 13:23:07

Title: socket script
Post by: Hamachi on 08 February, 2012, 13:23:07
Hey hope some like to help :)

I try to make a socket script there connect to irc server, need to be online all the time.

My script works as lua script.lua but then i run it whit px it make px not responde.
some of the code:
    -- Run main loop
    while true do
        local l = s:receive()
        --some code
    end

Hope someone can help or say it not will work
Title: Re: socket script
Post by: PPK on 08 February, 2012, 15:19:21
You are creating never ending loop in script, so PtokaX is blocked by that script and can't work  ::)
Title: Re: socket script
Post by: Hamachi on 08 February, 2012, 22:17:00
Yes :D

But how to make a socket connection then ?

the connection need to be open all the time....
Title: Re: socket script
Post by: PPK on 08 February, 2012, 22:39:02
Create socket, connect to server and then on timer (for example every second) try to read or send data on that socket (basically that is how PtokaX works) :P
Title: Re: socket script
Post by: Hamachi on 08 February, 2012, 22:47:18
ok thanks :)

I have a another script there download a file whit socket, if it take longtime it not response too.
Have you any ide for that ?

I use timeout in one script but in this i need the file...
Title: Re: socket script
Post by: PPK on 09 February, 2012, 13:18:10
It is always same. Create socket, connect socket, set it nonblocking (or zero timeout with select) and then in some intervals try to read/write. Never do loops on read/writes  ::)
Title: Re: socket script
Post by: Hamachi on 09 February, 2012, 14:07:32
Ok I will look in to it :)

Thanks for you help and time PPK
Title: Re: socket script
Post by: Hamachi on 09 February, 2012, 18:47:58
It works almost now :)

First time it find/write it dont respone in some time and then post it. :(

i dont understand this:
set it nonblocking (or zero timeout with select)
Title: Re: socket script
Post by: PPK on 09 February, 2012, 19:22:03
It is in luasocket docs :P
QuoteChanges the timeout values for the object. By default, all I/O operations are blocking. That is, any call to the methods send, receive, and accept will block indefinitely, until the operation completes. The settimeout method defines a limit on the amount of time the I/O methods can block. When a timeout is set and the specified amount of time has elapsed, the affected methods give up and fail with an error code.
Looks like real non-blocking is always not supported, so low (zero ?) timeout is needed ::)
Title: Re: socket script
Post by: Hamachi on 11 February, 2012, 19:03:18
Thanks agen PPK :)

Now i only have some text problems hehe :)

1 (1-15) need to remove them