Note that there are some explanatory texts on larger screens.

plurals
  1. POFile Transfer - Packet Rounds
    primarykey
    data
    text
    <p>I'm basically using a 20,480byte buffer that is into a packet structure. Here is the structure:</p> <pre><code>struct PACKET { DWORD Header; char data[20480]; bool eof; }; </code></pre> <p>What I'm doing is reading a file 20,480bytes at a time and sending it until all the file has been sent. I am testing this on a 3MB file and roughly 150 rounds are sent.</p> <p>Here is the code: </p> <pre><code>PACKET sc; sc.Header = 0xB; ifstream file("test.pdf", ios::ate | ios::binary | ios::in); DWORD fileSize = file.tellg(); file.seekg(0, ios::beg) int counter = 20480; int rounds = fileSize / 20480 + 1; </code></pre> <p>And the sending loop:</p> <pre><code>while (rounds != 0) { sc.eof = false; file.read(sc.data, sizeof(sc.data)); send(Slick.client, (char*)&amp;sc, sizeof(sc), 0); file.seekg(counter + 1); counter = counter + 20480; rounds--; Sleep(1); if (rounds == 0) sc.eof = true; cout &lt;&lt; "Left to send: " &lt;&lt; rounds &lt;&lt; endl; } file.close(); cout &lt;&lt; "All data was sent!" &lt;&lt; endl; </code></pre> <p>I'm using asynchronous sockets on the other side, so my problem is that sometimes it receives 140 packets, sometimes 130, 147, 148 etc and the file is always corrupted. What am I doing wrong?</p> <hr> <p>Here is the other side:</p> <pre><code>case PACKET_FILE: { if (isOpen == false) { isOpen = true; file.open("tester.pdf", ios::binary | ios::out | ios::app); file.write(pack.data, sizeof(pack.data)); } else { if (pack.eof == true) { file.write(pack.data, sizeof(pack.data)); file.close(); MessageBox(NULL, "File Received", "LOL", MB_OK); break; } file.write(pack.data, sizeof(pack.data)); } countz++; char bue[10]; itoa(countz, bue, 10); SendMessage(hlabelPackets, WM_SETTEXT, NULL, (LPARAM)(bue)); break; } </code></pre> <p>Please help, it makes no sense...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload