danarmstrong 0 Newbie Poster

I am attempting to read binary data from a server using the Winsock2 API. The following is the code I am using to receive the data. The data is received but doesn't match what it should be. I have tested this by entering the url in my browser and comparing the results of the file that is downloaded.

int contentLength = //this value is correctly parsed from the header previously recieved.
char recvBuf[1024];
int curRead = 0;
std::string message;

while(byte != contentLength)  {
	curRead = recv(sock,recvBuf,1023,0);
	byte += curRead;

	for(int x = 0; x < curRead; ++x) {
		message += shortToHex((short)recvBuf[x]);
	}
}

The function above returns the following data:

ff ac ff ed 00 05 75 72 00 02 5b 42 ff ac ff f3
17 ff f8 06 08 54 ff e0 02 00 00 78 70 00 00 00
2d 46 41 49 4c 45 44 3a 20 6a 61 76 61 2e 6c 61
6e 67 2e 4e 75 6d 62 65 72 46 6f 72 6d 61 74 45
78 63 65 70 74 69 6f 6e 3a 20 6e 75 6c 6c

The correct data is:

ac ed 00 05 75 72 00 02 5b 42 ac f3 17 f8 06 08
54 e0 02 00 00 78 70 00 00 00 21 a5 03 20 20 20 
20 20 20 75 65 73 74 65 72 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 ee ee 01

Any ideas of where I may be going wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.