mIRC Home    About    Download    Register    News    Help

Print Thread
#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?

Joined: Dec 2002
Posts: 503
B
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.

Joined: Dec 2002
Posts: 3,547
S
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) ..
}

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

Joined: Dec 2002
Posts: 3,547
S
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

Joined: Jan 2007
Posts: 1,156
D
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.

Joined: Dec 2002
Posts: 503
B
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.


Link Copied to Clipboard