mIRC Home    About    Download    Register    News    Help

Print Thread
sockread from the helpfile #186571 23/09/07 09:31 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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?

Re: sockread from the helpfile [Re: pouncer] #186573 23/09/07 09:33 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
That should work, but yes. Most people use a 'while' loop instead of the older 'goto' methods.

Re: sockread from the helpfile [Re: Bekar] #186574 23/09/07 09:38 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
And then there's some that don't use loops, like myself.

Code:
On *:Sockread:sock: {
  var %tmp
  sockread %tmp
  if (something isin %tmp) ..
}

Re: sockread from the helpfile [Re: SladeKraven] #186581 23/09/07 09:57 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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

Re: sockread from the helpfile [Re: pouncer] #186583 23/09/07 10:00 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Re: sockread from the helpfile [Re: SladeKraven] #186587 23/09/07 10:44 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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.

Re: sockread from the helpfile [Re: DJ_Sol] #186592 23/09/07 11:45 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
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.