mIRC Homepage
Posted By: pouncer sockread from the helpfile - 23/09/07 09:31 PM
Code:
Example:

This example shows you how you should process a sockread event. The socket has already been opened and has received information, so the sockread event is triggered. The socket name is testing. There is an explanation of each step below the sample script.


on 1:sockread:testing:{

if ($sockerr > 0) return

:nextread

sockread %temp

if ($sockbr == 0) return

if (%temp == $null) %temp = -

echo 4 %temp

goto nextread

}


thats from the mIRC help saying thats how it should be processed, but i never see sockread events like this using goto and stuff. is this an outdated help file or something?
Posted By: Bekar Re: sockread from the helpfile - 23/09/07 09:33 PM
That should work, but yes. Most people use a 'while' loop instead of the older 'goto' methods.
Posted By: SladeKraven Re: sockread from the helpfile - 23/09/07 09:38 PM
And then there's some that don't use loops, like myself.

Code:
On *:Sockread:sock: {
  var %tmp
  sockread %tmp
  if (something isin %tmp) ..
}
Posted By: pouncer Re: sockread from the helpfile - 23/09/07 09:57 PM
yep thats what i do slade except i also tokenize after the sockread %tmp so i can check $1 $2 $3 etc

i dont understand why loops and stuff are needed at all
Posted By: SladeKraven Re: sockread from the helpfile - 23/09/07 10:00 PM
I remember a discussion about goto loops and such in the On Sockread event but I can't seem to find it. They probably were needed back then, otherwise Khaled probably wouldn't have put that in the sockread event in the first place. But don't quote me on that though. smile
Posted By: DJ_Sol Re: sockread from the helpfile - 23/09/07 10:44 PM
I think the point to using goto or while is if the line is continued on the next line or is too big for tokenize. I wasn;t very clear on that though. I wish I knew because I've had issues where the line gets broken up into two lines occasionally.

This happened to be with a room list. Sometimes the topic is so long so the user count and language arent found on that line but the next line. I thought using this goto or while loop would allow me to consider it the same line, but I wasn't very sure.
Posted By: Bekar Re: sockread from the helpfile - 23/09/07 11:45 PM
When pulling from a socket, the packet size is how much data is read by the 'sockread'.

Using a while/goto loop will process all the queued data in the one event trigger, as against re-triggering the event over-and-over.

During the re-triggering of the event, it's possible (but doubtful) that another even tcould trigger, thus changing the environment scope..

But I guess it all depends on how you've written your event.
© mIRC Discussion Forums