mIRC Home    About    Download    Register    News    Help

Print Thread
sockread prob #15195 13/03/03 08:07 PM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
I did a sockread on http[/b]://www.ns.nl/binnenland/index.cgi, and it only returns untill a javascript commented line ( // )
Code:
 
alias test_open {
  if ($sock(test)) { sockclose test }
  sockopen test www.ns.nl 80
}
 
on *:sockopen:test: {
  if ($sockerr) { 
    echo -ati3 SOCKET: error $sockname > ip: $sock($sockname).ip $chr(124) $&
      port: $sock($sockname).port $chr(124) $&
      status: $sock($sockname).status $chr(124) $& 
      source address: $sock($sockname).saddr $chr(124) $&
      source port: $sock($sockname).sport 
  }
  else {
    echo -ati3 SOCKET: open $sockname > ip: $sock($sockname).ip $chr(124) $&
      port: $sock($sockname).port $chr(124) $&
      status: $sock($sockname).status $chr(124) $&
      source address: $sock($sockname).saddr $chr(124) $&
      source port: $sock($sockname).sport
    sockwrite -n $sockname GET /binnenland/index.cgi HTTP/1.1
    sockwrite -n $sockname Host: www.ns.nl
    sockwrite -n $sockname $crlf
  }
}
 
on *:sockread:test:{
  if ($sockerr) { 
    echo -ati3 SOCKET: error $sockname > ip: $sock($sockname).ip $chr(124) $&
      port: $sock($sockname).port $chr(124) $&
      status: $sock($sockname).status $chr(124) $&
      source address: $sock($sockname).saddr $chr(124) $&
      source port: $sock($sockname).sport
    return 
  }
  :READ
  sockread %test
  if (!$sockbr) {
    echo -ati3 SOCKET: close $sockname > ip: $sock($sockname).ip $chr(124) $&
      port: $sock($sockname).port $chr(124) $&
      status: $sock($sockname).status $chr(124) $&
      source address: $sock($sockname).saddr $chr(124) $&
      source port: $sock($sockname).sport
    sockclose $sockname
    return 
  }
  else {
    echo -ati3 $sockbr > %test
  }
  GOTO READ
}

Last edited by Hammer; 15/03/03 01:30 PM.

If it ain't broken, don't fix it!
Re: sockread prob #15196 13/03/03 09:28 PM
Joined: Feb 2003
Posts: 32
P
praetorian_ Offline
Ameglian cow
Offline
Ameglian cow
P
Joined: Feb 2003
Posts: 32
you are closing the socket when $sockbr evaluates to zero ($null), so you only get information up to the first time $sockbr is zero.

try this code instead:
Code:

on *:sockread:test:{ 
  if ($sockerr) { 
    echo -ati3 SOCKET: error $sockname > ip: $sock($sockname).ip $chr(124) $&
      port: $sock($sockname).port
    return 
  }
  :read
  sockread %test
  if (%test) { echo -ati3 $sockbr > %test }
  if ($sockbr) { goto read }
}

in this case, $sockbr is checked to see if anything was read and if so, does another read to look for extra data. if $sockbr is zero, it ends the procedure. note that information from sockets comes in packets, so there are multiple on sockread events for each download.

Last edited by Hammer; 15/03/03 01:31 PM.
Re: sockread prob #15197 15/03/03 09:57 AM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
but $sockbr is only zero at end of file...

all blank lines you encounter still have the $crlf chars so the length of those is 2 (I tested it with a smaller text file)


If it ain't broken, don't fix it!
Re: sockread prob #15198 15/03/03 01:25 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
but $sockbr is only zero at end of file...

That's not necessarily true. Here's why:

The web server sends data into your socket's Receive Queue (RQ) buffer (max size is 8192 bytes). When mIRC detects that there is data to be read in from the socket, it fires the on SOCKREAD event.

The on SOCKREAD event reads data from the RQ into a variable. $sock($sockname).rq tells you how many bytes are currently queued up, waiting to be read. As you read the data into your variable, it's removed from the RQ. That means there is no set size for the amount of data waiting to be read. Indeed, your socket might very well get in more data while it's processing the current data.

If you don't do a loop in on SOCKREAD, the event gets retriggered; however, that's not as efficient as looping while you're already in the on SOCKREAD event since you might have to handle other events in the meantime before managing to make it back to the on SOCKREAD event).

Remember that it might very well take several on SOCKREAD events to get the entire file. This is because you might process all the data on the socket before the server sends you more data (more of the rest of the file). If your script processes it all, then $sockbr becomes 0 because there is no more data waiting to be read CURRENTLY...the server hasn't sent anymore yet.

If you are sockclosing the socket before all the data is read, then you miss out on everything past the first on SOCKREAD event...the rest of the file.

You don't really need to close the socket since the web server will terminate it remotely. Just keep reading till you get all the information in and let the socket close itself.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: sockread prob #15199 19/03/03 05:31 PM
Joined: Jan 2003
Posts: 1,063
D
Doqnach Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
okay... could you post an example script with your additions to it? :-]

I've done alot of mIRC scripting, but never saw the need for sockets ;-] now I'm trying some stuff out and it aint working 100% hehehe


If it ain't broken, don't fix it!