Author Topic: socket script  (Read 2216 times)

0 Members and 1 Guest are viewing this topic.

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
socket script
« 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

PtokaX forum

socket script
« on: 08 February, 2012, 13:23:07 »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: socket script
« Reply #1 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  ::)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: socket script
« Reply #2 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....

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: socket script
« Reply #3 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
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: socket script
« Reply #4 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...

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: socket script
« Reply #5 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  ::)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: socket script
« Reply #6 on: 09 February, 2012, 14:07:32 »
Ok I will look in to it :)

Thanks for you help and time PPK

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: socket script
« Reply #7 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)

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: socket script
« Reply #8 on: 09 February, 2012, 19:22:03 »
It is in luasocket docs :P
Quote
Changes 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 ::)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: socket script
« Reply #9 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

PtokaX forum

Re: socket script
« Reply #9 on: 11 February, 2012, 19:03:18 »