I need to implement sisimple download resume function to my program but I really don'n know how. I tried to catch sometihing from Iczelion's tut on HTTP but it is to complicated for beginner as me. Do you have any code snipet with comment or somethig exasy for me? Thank you.
Posted on 2001-04-24 16:07:00 by raguru
I presume you already got a working http download routine, that doesnt support resuming. In order to download a certain part of a file through http I think you should something like this to the server: " GET http://domain.xx/path/file HTTP/1.1 range: bytes startbyte-endbyte " Note that the last line must only contain CR/LF. This message was edited by Ahner, on 4/24/2001 8:59:21 PM
Posted on 2001-04-24 19:34:00 by Ahner
I am not sure what yuou mean with it. I have this code. It works but I don't know how to implement to it what you have mentioned above. CODE>>>>>> ////////////////////////// ////////////////////////// invoke WSAStartup, 01h, addr ws_data ;initialize winsock invoke gethostbyname, addr server ;look up the IP .IF eax==NULL invoke WSACleanup invoke Sleep,10000 JMP TryToConn ;invoke ExitProcess, NULL .ENDIF mov eax, mov eax, mov eax, mov hostinfo.sin_addr, eax invoke htons, port ;convert port to network order mov hostinfo.sin_port, ax ;port is word sized mov hostinfo.sin_family, AF_INET invoke socket, PF_INET, SOCK_STREAM, 0 ;obtain a socket mov oursocket, eax ;-------------------- invoke CreateFile, addr filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL mov filehandle, eax ;-------------------- invoke connect, oursocket, addr hostinfo, SIZEOF sockaddr_in ;connect the socket invoke wsprintf, addr databuffer, addr request, addr url ;format the http request invoke send, oursocket, addr databuffer, eax, NULL ;send the http request .WHILE keepgoing == TRUE invoke recv, oursocket, addr databuffer, BUFFERSIZE, NULL ;recive some data .IF eax==NULL mov keepgoing, FALSE ;server disconnected us invoke CloseHandle, filehandle ;-------------------------------------- invoke FileAtHome ; a je to doma ;-------------------------------------- .ELSEIF eax==SOCKET_ERROR mov keepgoing, FALSE ;another error occured .ELSEIF eax>0 mov bytesrecvd, eax mov esi, offset databuffer .IF headerflag==TRUE ;// This is our first recv so we have to strip away the http header ;// that comes before the file invoke getHeaderLength, addr databuffer sub bytesrecvd, eax add esi, eax mov headerflag, FALSE .ENDIF invoke WriteFile, filehandle, esi, bytesrecvd, addr junkstorage, NULL .ENDIF .ENDW invoke closesocket, oursocket invoke WSACleanup invoke ExitProcess, NULL ;===================================================================== ;getHeaderLength() ;===================================================================== getHeaderLength PROC lpBuffer:DWORD push esi mov esi, lpBuffer mov ecx, BUFFERSIZE @@: cmp dword ptr , 0a0d0a0dh je @F inc esi loop @B @@: add esi, 4 sub esi, lpBuffer mov eax, esi pop esi ret getHeaderLength ENDP //////////////////////////// //////////////////////////// Would you be so kind and help me. Thanx
Posted on 2001-04-25 16:13:00 by raguru
Sadly Im not too good at asm, and I only have I vague idea of how the http stuff works, just started looking into it. But if I am allowed to take a chance, try replacing invoke wsprintf, addr databuffer, addr request, addr url with invoke wsprintf, addr databuffer, addr request, addr url, addr httpver, downloadoffset, addr endget And add this to your data declarations httpver db " HTTP/1.0",0dh,0ah, "Range: bytes=" downloadoffset dd 0 endget db "-",0dh,0ah,0dh,0ah And pray, alot!:P
Posted on 2001-04-25 17:57:00 by Ahner