Sockets breaking loop - 06/04/13 03:29 AM
Hello there!
I have a question regarding sockets and their proper use. i wrote a script over the last few days including the following part:
The script works without any proplem as long as the timer won't be interrupted for some reason and even if,
the socket will be closed automatically after approximately 30 sec which will reset all %dict. vars as well.
But i want to use some %dict. vars for a different Trigger to initiate onetime events.
If it happens now, that one of these %dict. vars is accidentally set in the 30 sec or even in the 2 sec until the timer runs out,
the Var will be reset together with all other %dict. Vars and the script won't be executed properly.
And sometimes the reading process takes to to long and an error occurs even if there was a match.
To get to the point, i want to replace the timer with a comparison in the SOCKREAD Trigger, so the process to reset the %dict. Vars is faster in general and to make the funktion more resistant against various errors.
I tried already to find a solution by using different Socket parameter like &sock(dict).rq and compare them,
but everything i tried (and i tried a lot) didn't work.
Sadly it's not possible to add another boolean comparison like this:
I'm running out of options and have absolutely no clue how to fix this issue, so i thought maybe anyone here has a solution to offer and can give me a nudge in the right direction.
Any help is greatly appreciated!
I have a question regarding sockets and their proper use. i wrote a script over the last few days including the following part:
Code:
alias -l dict { set %dict.term $$1- set %dict.url /?s= $+ $replace($$1-,$chr(32),+) sockopen dict www.dict.cc 80 ; ------------------------ timerdict.autoreset 1 2 dictautoreset ; ------------------------ } ; ------------------------ alias -l dictautoreset { msg %dict.recipient 4***Error 14 No Match for <14 %dict.term >14. Please visit7 www.dict.cc $+ %dict.url 14for more information. unset %dict.* sockclose dict } ; ------------------------ on *:SOCKOPEN:dict:{ sockwrite -nt $sockname GET %dict.url HTTP/1.1 sockwrite -nt $sockname HOST: www.dict.cc sockwrite -n $sockname } on *:SOCKREAD:dict: { if ($sockerr > 0) { echo -a Error while reading from $sockname $+ . | echo -a Error # $+ $sockerr occurred. | return } sockread %dict.read while ($sockbr) { if ($regex(%dict.read,var c.Arr = new Array)) { if ($mid(%dict.read,6,1) == 1) { ; ------------------------ timerdict.autoreset off ; ------------------------ set %dict.text.eng %dict.read } if ($mid(%dict.read,6,1) == 2) { set %dict.valid.result 1 set %dict.text.deu %dict.read dict.form halt } } sockread %dict.read } } on *:SOCKCLOSE:dict: { msg %dict.recipient 4***Error14 - No match, please visit7 www.dict.cc $+ %dict.url 14for more information | unset %dict.* } alias -l dict.form { Set %dict.char.remove 1 msg %dict.recipient <14 %dict.term > 7Dict.cc14 Translation 12English - 3Deutsch while (%dict.char.remove <= %dictresultcount) { Set %dict.word.eng.out $remove($remove($mid(%dict.text.eng,$pos(%dict.text.eng," $+ $chr(44) $+ ",%dict.char.remove),$calc($pos(%dict.text.eng," $+ $chr(44) $+ ",$calc(%dict.char.remove + 1)) - $pos(%dict.text.eng," $+ $chr(44) $+ ",%dict.char.remove)))," $+ $chr(44) $+ "),",\) Set %dict.word.deu.out $remove($remove($mid(%dict.text.deu,$pos(%dict.text.deu," $+ $chr(44) $+ ",%dict.char.remove),$calc($pos(%dict.text.deu," $+ $chr(44) $+ ",$calc(%dict.char.remove + 1)) - $pos(%dict.text.deu," $+ $chr(44) $+ ",%dict.char.remove)))," $+ $chr(44) $+ "),",\) if (%dict.word.eng.out) { msg %dict.recipient 12 %dict.word.eng.out -3 %dict.word.deu.out } inc %dict.char.remove } msg %dict.recipient 14for more information visit7 www.dict.cc $+ %dict.url unset %dict.* sockclose dict }
The script works without any proplem as long as the timer won't be interrupted for some reason and even if,
the socket will be closed automatically after approximately 30 sec which will reset all %dict. vars as well.
But i want to use some %dict. vars for a different Trigger to initiate onetime events.
If it happens now, that one of these %dict. vars is accidentally set in the 30 sec or even in the 2 sec until the timer runs out,
the Var will be reset together with all other %dict. Vars and the script won't be executed properly.
And sometimes the reading process takes to to long and an error occurs even if there was a match.
To get to the point, i want to replace the timer with a comparison in the SOCKREAD Trigger, so the process to reset the %dict. Vars is faster in general and to make the funktion more resistant against various errors.
I tried already to find a solution by using different Socket parameter like &sock(dict).rq and compare them,
but everything i tried (and i tried a lot) didn't work.
Sadly it's not possible to add another boolean comparison like this:
Code:
if ($regex(%dict.read,re) { unset %dict.* sockclose dict halt }
I'm running out of options and have absolutely no clue how to fix this issue, so i thought maybe anyone here has a solution to offer and can give me a nudge in the right direction.
Any help is greatly appreciated!