mIRC Home    About    Download    Register    News    Help

Print Thread
More socket help... #19789 17/04/03 10:41 AM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
I need the socket to return the filesize of the file its going to download... How do i do that?

Thanks for any help!

Re: More socket help... #19790 17/04/03 12:28 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Check the sockread for "Content-Length: NNN" NNN is the filesize.

Re: More socket help... #19791 17/04/03 12:29 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
Hu?

Re: More socket help... #19792 17/04/03 12:50 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Code:
on *:SOCKREAD:sockname:{
  if $sockerr { return }
  ; Determine if you should be reading to &bvar (the file itself) or %var (the header)
  if whatever {
    var %read
    sockread %read
    if [color:green]Content-Length: [color:blue]*[/color] iswm %read[/color] { do stuff with the [color:blue]*[/color] }
    ..
  }
  else {
    sockread &var
    ..
  }
}

Re: More socket help... #19793 17/04/03 01:05 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
I dont understand it.... So.. Anyone else that can explain it for me? Thanks for your help anyway!

Re: More socket help... #19794 17/04/03 04:04 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
OK: When you request a file, the server will send some info to you, and then the file (if it exists).

Some thing like this, if the file you requested wasn't found.
HTTP/1.0 404 Not Found
Date: Thu, 17 Apr 2003 16:06:22 GMT
Server: Apache/2.0.40 (Red Hat Linux)
...
...


or this..

HTTP/1.0 200 OK
Date: Thu, 17 Apr 2003 15:57:00 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Last-Modified: Fri, 16 Aug 2002 20:21:15 GMT
ETag: "23c04b-16806-f6b8e4c0"
Accept-Ranges: bytes
[color:blue]Content-Length: 92166

Content-Type: application/zip
<blank line>
..binary file data
..binary file data
...
..
etc.[/color]

This, "Content-Length: 92166", is the info you want. In this example the file was 92166 bytes.

So to get it you need to "/sockread %var" and parse %var to find the info.
e.g. if Content-Length: * iswm %var { set %file.size $gettok(%var,2,32) }
When "%var == $null" is when the actual file will begin to download, at that time you switch to "/sockread &bvar".

Re: More socket help... #19795 17/04/03 04:21 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
I cant get it to work..
I have this now:
Code:
 
on *:sockread:download:{
  sockread %size
  if (Content-Length: * iswm %size) { set %file.size $gettok(%size,2,32) }
  did -a update.now 2 %file.size
  :loop
  if ($sockerr &gt; 0) return
  sockread &amp;temp
  if (!$sockbr) return
  bwrite %version $+ .exe -1 &amp;temp
  did -ra update.now 4 $bytes($sock(download).rcvd,m3).suf
  did -ra update.now 6 $dur($sock(download).to)
  goto loop
}
 


What is wrong here? Thanks!

Re: More socket help... #19796 17/04/03 04:51 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
You have to loop for the header lines, and again for the file.
Code:
on *:sockread:download:{
  if $sockerr { echo -eat * Socket error: $sock(download).wserr $sock(download).wsmsg }
  while !$sock($sockname).mark {
    sockread %size
    if (Content-Length: * iswm %size) {
      set %file.size $gettok(%size,2,32)
      did -a update.now 2 %file.size
    }
    if !%size { sockmark $sockname $ticks | echo -sg $sock($sockname).mark }
  }
  while $sock($sockname) {
    sockread &amp;temp
    if (!$sockbr) return
    bwrite %version $+ .exe -1 &amp;temp
    did -ra update.now 4 $bytes($sock(download).rcvd,m3).suf
    did -ra update.now 6 $dur($sock(download).to)
    if $file(%version $+ .exe).size == %file.size {
      echo -eat * %version $+ .exe downloaded in $calc(($ticks - $sock($sockname).mark)*.001) secs
    }
  }
}

Re: More socket help... #19797 17/04/03 05:07 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
No! It still doesn`t work!

It keeps echoing out the
"if (!%size) { sockmark $sockname $ticks | echo -ag $sock($sockname).mark }".

Exept from that it`s still the same... And it downloads the file as well...

Re: More socket help... #19798 17/04/03 05:14 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
OOps well that line should have been
if !%size { sockmark $sockname $ticks }
the echo was for myself when I tested it, and it did work for me smile

Re: More socket help... #19799 17/04/03 05:44 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
Nothing changed... didn`t echo though... it downloads but it doesn`t put the file size in the dialog (did -a update.now 2 %file.size)

Re: More socket help... #19800 17/04/03 06:06 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Check your dialog name & id numbers. the "/did " lines work here.

Re: More socket help... #19801 17/04/03 06:12 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
It`s correct.

dialog update.now {
text "File size:", 1, 40 20 60 30
text "", 2, 72 20 50 30
}
this is just the relevant part of the dialog.
Code:
  on *:sockread:download:{  
  if ($sockerr) { 
  echo -eat * Socket error: $sock(download).wserr $sock(download).wsmsg } 
  while (!$sock($sockname).mark) {   
    var %size
    sockread %size    
    if (Content-Length: * iswm %size) {   
      set %file.size $gettok(%size,2,32)   
      did -a update.now 2 %file.size 
    }  
 

This is just the relevant part of the algorithm...
As you see there is n`t anything wrong... Al the other functions in the dialog work properly, just not the filesize returner...

This is the sockopen command:
on *:sockopen:download:{
sockwrite -n $sockname GET /knappen/ $+ %version $+ .exe
}
Does this have anything to do with it?

Re: More socket help... #19802 17/04/03 06:43 PM
Joined: Dec 2002
Posts: 699
N
Nimue Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Quote:
text "File size:", 1, 40 20 60 30
text "", 2, 72 20 50 30

Those overlap, perhaps you're hiding it.
Code:
ID1 (x40)|      |
ID2    (x72)|     |

Re: More socket help... #19803 17/04/03 06:48 PM
Joined: Jan 2003
Posts: 148
K
Knappen Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Jan 2003
Posts: 148
No, that`s not the problem... It just wont show... I tried to echo it but it doesn`t do that either... I dont think it sets the var..