mIRC Homepage
Posted By: pouncer question on sockread - 13/09/06 01:07 AM
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?
Posted By: SCNDRL Re: question on sockread - 13/09/06 02:52 PM
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..
Posted By: Rand Re: question on sockread - 14/09/06 07:17 AM
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. }
Posted By: pouncer Re: question on sockread - 14/09/06 10:32 AM
thanks alot mate.

and on the sockopen isnt this better?

if ($Sockerr) {
echo error $Sockname $Sockerr $sock($Sockname).wsmsg
halt
}
Posted By: hixxy Re: question on sockread - 14/09/06 10:37 AM
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.
© mIRC Discussion Forums