WSARecv and IOCP :: Winsock

This is a discussion on WSARecv and IOCP :: Winsock within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I am working on a network client and one of its features is download files over HTTP server, i.e. ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    WSARecv and IOCP :: Winsock

    Hi.

    I am working on a network client and one of its features is download files over HTTP server, i.e. www.abc-xyz.com/files.exe. The program downloads some files successfully, but it fails to download some files. For some reason, it download the all files, but some files are unvalid in terms of CRC.

    I understand that the server initially sends information about a file including its size and type (Content-Type). However, for some reason files that have bad CRC seem to miss the beginning chunk of data. In other words, the program does the file, but the first twenty bytes might contain bad CRC. Here is the algorithm of the design.

    - Send request (GET)
    - Call WSARecv
    - On first incoming data, analyze data and determine file size.
    - Analyze data and save any valid data that server might have including with file information.
    - Call WSARecv
    - Continue calling WSARecv and appending new data until size of data equals the size that the server sent.

    I would like to know is it possible that the server sends out the data before it sends out information about the data such as size? With the algorithm above, the program can download some file, but fails other files in terms of CRC. I cannot understand how that is possible because the size of the file is correct most of the time, but even so the files have bad CRC. Another interesting fact is that the bad CRC always occurs at the beginning such as the first 20 bytes.

    Thanks,
    Kuphryn

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>is it possible that the server sends out the data before it sends out information about the data such as size?
    Not really, imho. The server will send things out in the correct order, and the TCP protocol will ensure the packets get to you in the same order. So unless the server is screwy, I'd say this wasn't your problem.

    Does it always mess up the same file?
    Have you managed to work out what data it should have written, is there any pattern between that and the data it actually wrote?
    You could do a network trace to watch the data going to your PC.
    Is it possible you've mis-interpretting the header, starting to write data to the file at the wrong point in the process?
    I suggest you create a second file, and output everything you receive to it, headers and all. That process would be simpler, as you don't need to parse the header. With this, you may be able to spot your problem.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    The problem has to do with the fact that the program used a pointer to the actual IOCP buffer to write to the file. WriteFile corrupted the buffer. One solution is to use memcpy() to copy the most current buffer to temporary memory and then write it to disk.

    Kuphryn

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,657
    Interesting. Any idea why WriteFile corrupted the data like that?



    ITSA
    Socket Library!

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I think WriteFile keeps IOCP from updating the buffer with incoming data.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. AcceptEx with WSASend and WSARecv :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-05-2003, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21