mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2003
Posts: 64
M
Babel fish
OP Offline
Babel fish
M
Joined: Jan 2003
Posts: 64
Hi there fellas, it's been awhile for me! I have and this is actually the second time I've run into this issue, a /sockread obstacle where a script can't read the full page. So as an example I'm going to test this on drudgereport.com and we'll see what happens.

Code:
alias testgo.open {
  sockopen testgo drudgereport.com 80
}
on 1:sockopen:testgo:{
  var %a = .sockwrite -n testgo 
  %a GET / HTTP/1.0
  %a Accept: */*
  %a Referer: http://www.drudgereport.com/
  %a Accept-Language: en-us
  %a UA-CPU: x86
  %a Accept-Encoding: No Compression
  %a Connection: Keep-Alive
  %a Host: drudgereport.com
  %a $crlf
}
on 1:sockread:testgo:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) { 
    sockclose testgo
    echo $chr(160)
    return 
  }
  if (%temp == $null) %temp = -
  echo 4 %temp
  goto nextread
}


You'll note that this last sockread code is pretty much straight out of the mIRC faq guide, even the goto is the same.

So we can run this with /testgo.open. We get a number of lines of html back correctly, but we don't get the whole page. It tends to stop around the first story headline. Any pointers would be greatly appreciated.

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Originally Posted By: MegaZeroX
Hi there fellas, it's been awhile for me! I have and this is actually the second time I've run into this issue, a /sockread obstacle where a script can't read the full page. So as an example I'm going to test this on drudgereport.com and we'll see what happens.

Code:
alias testgo.open {
  sockopen testgo drudgereport.com 80
}
on 1:sockopen:testgo:{
  var %a = .sockwrite -n testgo 
  %a GET / HTTP/1.0
  %a Accept: */*
  %a Referer: http://www.drudgereport.com/
  %a Accept-Language: en-us
  %a UA-CPU: x86
  %a Accept-Encoding: No Compression
  %a Connection: Keep-Alive
  %a Host: drudgereport.com
  %a $crlf
}
on 1:sockread:testgo:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) { 
    sockclose testgo
    echo $chr(160)
    return 
  }
  if (%temp == $null) %temp = -
  echo 4 %temp
  goto nextread
}


You'll note that this last sockread code is pretty much straight out of the mIRC faq guide, even the goto is the same.

So we can run this with /testgo.open. We get a number of lines of html back correctly, but we don't get the whole page. It tends to stop around the first story headline. Any pointers would be greatly appreciated.


To start you have to much code in your sockread call here is a revised version to dump the full HTML

Code:
on 1:sockread:testgo:{
  if ($sockerr > 0) return
  var %temp | sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  echo -a %temp
}


if you want anything fancy in the read let me know, but I did what you asked :P I so hate goto's even in the LOOP instructions I rather use while loops if im gonna loop through. :P

Enjoy! cheers.

P.s> i forgot to mention that the sockclose testgo in your sockbr == 0 statement is not needed a simple return was sufficient I don't see any reason why you should call a socket close immediately, but it's entirely your choice I removed it out of the revised code I like to make things the smallest I can.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Jan 2003
Posts: 64
M
Babel fish
OP Offline
Babel fish
M
Joined: Jan 2003
Posts: 64
That's spectacular, works terrific! I really appreciate it!

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Originally Posted By: MegaZeroX
That's spectacular, works terrific! I really appreciate it!


Your welcome, at least you tried to read the mIRC help file alot of people ignore it, even in this case the explanation of sockreads are not much helpful. But other things are really helpful depends on what you need. So therefore you learn with time of what works and what doesn't and how to use what even if you never touched it since you started. Its like a baby learning new words and the meaning of it, later in years you'll learn different words but know the meaning of it.

laugh

Also if you dont want a - to appear in null locations are want a space "Empty" area remove the - in the script and hold CTRL and press I on your keyboard once, then save the script run your script youll see what I mean.

I didn't want to put that in the script live on here because if you edited your script and erase the empty spot by accident it would of let you wondering what you edited when you can't see it.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Link Copied to Clipboard