mIRC Homepage
Posted By: westor $sockread problem - 06/12/10 08:55 PM
I am trying to put to $sockread on one sockread event but an error is appear, The error is when the file trying to complete the download it stucks (halts) on the half progress, any ideas?

Code:
alias banlist_download {
  sockclose banlist_download
  echo -s banlist_download Connecting to www.westor.ucoz.com ...
  set %BL_DOWNLOAD_START_TIME $ctime
  sockopen banlist_download www.westor.ucoz.com 80
}

ON *:SOCKOPEN:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  echo -s $sockname Connected to westor.ucoz.com
  sockwrite -n $sockname GET /remotes/banlist.rar HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
  sockwrite -n $sockname Host: westor.ucoz.com
  sockwrite -n $sockname $crlf
}

ON *:SOCKREAD:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  var %s
  sockread %s
  sockread &temp
  if (content-length:* iswm %s) { echo -s $sockname $gettok(%s,2-,32) [SIZE] ! }
  if ($sockbr == 0) return
  bwrite " $+ $mircdirdownloads\banlist.rar $+ " -1 -1 &temp
  echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs
}


- Thanks!
Posted By: m0viefreak Re: $sockread problem - 07/12/10 11:59 AM
There are several mistakes:
1) you read TWICE on every sockread call, this results in half the data going to %s, and the other half to &temp
2) you don't distinguish between header data and user data, this results in some of the headers being written to your target file, thus making it invalid
3) echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs is called multiple times during the process

try something like this:
Code:
alias banlist_download {
  sockclose banlist_download
  echo -s banlist_download Connecting to www.westor.ucoz.com ...
  set %BL_DOWNLOAD_START_TIME $ctime
  sockopen banlist_download www.westor.ucoz.com 80
}

ON *:SOCKOPEN:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  echo -s $sockname Connected to westor.ucoz.com
  sockwrite -n $sockname GET /remotes/banlist.rar HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
  sockwrite -n $sockname Host: westor.ucoz.com
  sockwrite -n $sockname $crlf
}

ON *:SOCKREAD:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }

  ;; interpret as header data until we reach a null byte
  if (!$sock($sockname).mark) {
    var %s | sockread %s
    if (content-length:* iswm %s) { echo -s $sockname $gettok(%s,2-,32) [SIZE] ! }
    if (%s == $null) { sockmark $sockname 1 }
  }

  ;; null byte found, everything that comes next, is data
  else { sockread &temp | bwrite " $+ $mircdirdownloads\banlist.rar $+ " -1 -1 &temp }
}

on *:SOCKCLOSE:banlist_download: {
  echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs
}


also make sure you delete the .rar file each time before you start downloading, else it will just append to the end of the file! i.e. use something like
Code:
remove " $+ $mircdirdownloads\banlist.rar $+ "

at first line in your alias
Posted By: westor Re: $sockread problem - 07/12/10 03:53 PM
Thank you very much my friend!
© mIRC Discussion Forums