TransmitFile

This is a discussion on TransmitFile within the Networking/Device Communication forums, part of the General Programming Boards category; i have 2 questions about TransmitFile: 1) when i write 1 for the nNumberOfBytesPerSend argument, it should send the file ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    98

    TransmitFile

    i have 2 questions about TransmitFile:

    1) when i write 1 for the nNumberOfBytesPerSend argument, it should send the file byte by byte right? so why it doesn't send him this way? it sends the first 2 bytes in the first transmit, and all the rest in the second one.

    2) i want to send some data before and after the file, so i'm using the lpTransmitBuffers parameter:
    Code:
    char buff[] = "start";
    char buffb[] = "end";
    TRANSMIT_FILE_BUFFERS tfb;
    tfb.Head = buff;
    tfb.HeadLength = sizeof(buff);
    tfb.Tail = buffb;
    tfb.TailLength = sizeof(buffb);
    but it only sends the Head buffer and stops, it doesn't even send the file itself.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> 1) when i write 1 for the nNumberOfBytesPerSend argument, it should send the file byte by byte right? so why it doesn't send him this way? it sends the first 2 bytes in the first transmit, and all the rest in the second one. <<

    How do you know this? It may be calling send byte by byte but these are being combined into bigger transmits at a lower level. Alternatively the receiving computer may be combining multiple packets of received data into a bigger recv call. You can not expect a one to one relationship between send and recv with the TCP protocol.

    >> but it only sends the Head buffer and stops, it doesn't even send the file itself. <<

    Could you post your code? One thing I can think of is that you are transmitting a nul character at the end of the word "start". This means if you print out the received buffer it will stop at the first nul character and not print the file contents.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    98
    i gave the code...
    i changed the size from sizeof(buff) to 5 and it works now. but it prints the head buffer, the file and the tail buffer in one messagebox (the messagebox jumps with the data when a message received). i think it's because what u said before about the bytes being combined, but how can i seperate the head data from the file contents?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It is your responsibility to split up the data. One way you can do this is to transmit the length of each part of the data before the data. For example, you could transmit "5start100FileContents...3end" and then use the numbers to split up the data. Another way is to seperate the data using a special character. For example if you sperated the data with a nul character you could get each part with the following code:
    Code:
    char* start = buf;
    char* file = start + strlen(start) + 1;
    char* end = file + strlen(file) + 1;

Popular pages Recent additions subscribe to a feed

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