mIRC Home    About    Download    Register    News    Help

Print Thread
#159045 13/09/06 01:07 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Code:
on *:SOCKREAD:whatever*: {
  if ($sockerr) {
    echo -s error $sockname $sockerr $sock($sockname).wsmsg
    halt
  }

  var %r
  sockread %r
  while ($sockbr > 0) {
    tokenize 32 %r
    if stuff here..
    sockread %r
  }
}


shud sockreading be like that? good?

#159046 13/09/06 02:52 PM
Joined: Dec 2005
Posts: 58
S
Babel fish
Offline
Babel fish
S
Joined: Dec 2005
Posts: 58
yep but you should put this code on sockopen event
Code:
  if ($sockerr) {
    echo -s error $sockname $sockerr $sock($sockname).wsmsg
    halt
  }


also

Code:
while ($sockbr > 0) {


it s not necessary because when $sockbr is 0 sockread will stop automaticly..

here is wrong;
Code:
tokenize 32 %r
    if stuff here..
    sockread %r


u should use tokenize command after sockread command u can't tokenize unripe %variable. Like this ;

Code:
    sockread %r
    tokenize 32 %r
    if stuff here..


i couldn't see other problem smirk i hope it ll work..


i like that
#159047 14/09/06 07:17 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Try not to correct other people if you aren't too experienced at it in the first place. What he has works fine.

Code:
var %r
  sockread %r
  while ($sockbr > 0) {
    tokenize 32 %r
    if stuff here..
    sockread %r
  }


Since you don't seem to understand, I'll point a few things out to you, mIRC dumps text (up to the next CRLF) into the variable. This means that there can still be "downloaded" information in the sockread buffer, so when you perform a "sockread" at the bottom of the while loop, it grabs the new information, and you parse it at the top of the loop.

The way it's listed above is the fastest way to deal with sockets, as it empties the buffer, instead of retriggering the on sockread event unnecessarily. (This is mentioned in the mIRC help file.)

My only problem with this way of parsing webpages, is that when the buffer reaches the last bit of information, it spits it out, even though there isn't a CRLF to end the line.

This left me with having to deal with things like:
<a href="
http://..........">blah</a>

On two seperate parsed strings. Which is a pain in the ass. So I generally just make mIRC work the tough way, and just let it retrigger the event over and over again. Just my two cents.


As for the original poster: What you have there will work fine. Though you may want to add this in your "on sockopen" event: if ($sockerr) { echo -sg *** Couldn't connect to the server. }

#159048 14/09/06 10:32 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks alot mate.

and on the sockopen isnt this better?

if ($Sockerr) {
echo error $Sockname $Sockerr $sock($Sockname).wsmsg
halt
}

#159049 14/09/06 10:37 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
You should check for errors in a sockopen event, yes. There's no need in on sockread, since an error on an active socket will result in the socket closing. $sockerr should never be anything other than 0 in the sockread event as far as I know.

Edit: I see what you mean now. If you don't understand what the different winsock errors mean then that won't really help you, so it depends how knowledgeable you are really.


Link Copied to Clipboard