mIRC Homepage
Posted By: HaleyJ sockets help - 08/09/10 04:42 PM
Hi there,

Say I want to use sockets to download a text file like versions.txt what is the most reliable way to check the file has completed downloading?

I can use sockets to read the file etc, but want a reliable way to check that the download has completed!

I don't want to use the sockclose event as the socket in theory could close before the file has been downloaded. I guess I am looking for something similar to 200 ok response etc.

Any help or insights would be greatly appreciated.

Regards
Posted By: Voglea Re: sockets help - 08/09/10 04:47 PM
see Content-Length HTTP header, and when $file().size == content-length, then file downloaded.
Posted By: HaleyJ Re: sockets help - 12/09/10 07:40 PM
Originally Posted By: Voglea
see Content-Length HTTP header, and when $file().size == content-length, then file downloaded.


Just tested it and it does not work. I checked and $file().size differs from Content-length:
Posted By: Collective Re: sockets help - 12/09/10 09:20 PM
How much is it off by? Are you saving the HTTP headers in the file? Are you writing the file using binary variables? Let's see your code.
Posted By: Chessnut Re: sockets help - 12/09/10 10:56 PM
if you're interested, i wrote a script to download any file here: http://forum.swiftirc.net/viewtopic.php?f=34&t=18010
Posted By: HaleyJ Re: sockets help - 13/09/10 10:33 AM
I am not downloading the headers. Just the file. I parse the headers out.

It is off by 82. The Content-Length: is 6747 and the file().size returns 6829

Posted By: Chessnut Re: sockets help - 13/09/10 10:57 AM
It's quite possible that the server is responding with chunked data. Try changing HTTP/1.1 to HTTP/1.0 and see if that resolves your problem.
Posted By: 5618 Re: sockets help - 13/09/10 11:27 AM
Also, make sure you're not writing anything to file when the value of the sockread is $null.
Posted By: HaleyJ Re: sockets help - 13/09/10 12:39 PM
Originally Posted By: 5618
Also, make sure you're not writing anything to file when the value of the sockread is $null.


I have made sure of that, thanks
Posted By: HaleyJ Re: sockets help - 13/09/10 12:42 PM
Originally Posted By: Chessnut
It's quite possible that the server is responding with chunked data. Try changing HTTP/1.1 to HTTP/1.0 and see if that resolves your problem.


It has not resolved the problem. Same results as in my previous post.
Posted By: Wims Re: sockets help - 13/09/10 10:05 PM
A good thing to do would have been to show your code in your first post, or at least when it was explicity asked..
I'm sure you understand that people can't really help you with this just by guessing
Posted By: DJ_Sol Re: sockets help - 15/09/10 04:08 PM
I have a socket updater for my scripts. I have a version.txt sort of file uploaded on my server. I have text that says when it starts and ends so I didn't have to code to get past the headers. Less code, more direct. When reading this text file with a socket I found issues reading the last line. It was so long ago I can't remember them, but that is why I added the hyphen as the last line. My code looks for:

$1 = update, $2 = end, and knows its the end of the file.

My file looks like this.

update start
filename.mrc version
d_filename.mrc description
p_filename.mrc path
update end
-
© mIRC Discussion Forums