Thread: Recieving bad bytes

  1. #1
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640

    Recieving bad bytes

    Has anyone heard of a problem with recieving bad bytes? I am using my program to download a file (the google logo.gif) and byte for byte is the same except that any 0x00 bytes I should be recieving are shown/saved as 0x20 (the space character). I can not figure this out, every other byte is exactly the same.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I've never heard of anything like this happening before. Are you sure your code is correct?

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    it seems to be working fine. all the other bytes are being recieved ok. I did a byte compare and the only differences are that the recieved file has byte 0x20 where it should be 0x00. The only thing I can think of is because I'm requesting the file through http 1.1, that maybe it's a problem of some kind.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Post the relavent code here

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Code:
    		case FD_READ:
    			{
    				DWORD dwBytesWritten = 0;
    				int iBytesRecv = 0;
    				ZeroMemory(xbuff, 256);
    				ZeroMemory(tmpbuff, 350);
    
    				if (CaptureAsFile)
    				{
    					while (true)
    					{
    						ZeroMemory(xbuff, 256);
    						iBytesRecv = Client.Recv(xbuff, 256);
    						if ((iBytesRecv == 0) ||
    							(iBytesRecv == -1) ||
    							(iBytesRecv == SOCKET_ERROR))
    							break;
    						WriteFile(hCapFile, xbuff, iBytesRecv, &dwBytesWritten, NULL);
    					}
    
    					CaptureAsFile = false;
    					CloseHandle(hCapFile);
    				}
    Code:
    INT PEER::Recv(CHAR *databuff, INT len)
    {
    	if (wProtocol == TCP)
    	{
    		if ((iRecvBytes = recv(sckPeer, databuff, len, 0)) == SOCKET_ERROR)
    			if ((iError = WSAGetLastError()) != WSAEWOULDBLOCK)
    					return -1;
    		iTRecvBytes += iRecvBytes;
    		return iRecvBytes;
    	}
    	return -1;
    }
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Your code looks OK. I'm starting to think that the reason you are seeing 0x20 instead of 0x00 is from how you read the bytes. Are you using a different program to read the bytes you downloaded? It's possible that the program is trying to read the file as a text file instead of a binary file, and so it changes the bytes to 0x20. You should use a hex editor to read the file after you've downloaded it instead of a text editor.

  7. #7
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quote Originally Posted by bithub
    Your code looks OK. I'm starting to think that the reason you are seeing 0x20 instead of 0x00 is from how you read the bytes. Are you using a different program to read the bytes you downloaded? It's possible that the program is trying to read the file as a text file instead of a binary file, and so it changes the bytes to 0x20. You should use a hex editor to read the file after you've downloaded it instead of a text editor.

    Yes, I am using a hex editor. I view both the file my program downloaded and the the image saved to hard disk from firefox. The only difference is that 0-bytes are the 0x20. Could this be because of how the file is requested through http/1.1? Somehow the server wants to send it that way? The request I use is this:
    GET /intl/en/images/logo.gif HTTP/1.1
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  8. #8
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    So it seems when you open a file in notepad to delete content header information, then save it, 0x00 bytes are saved as 0x20. I had to find my old keyboard to type this response in.
    Last edited by neandrake; 03-06-2006 at 10:53 PM.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a file into a block
    By mickey0 in forum C++ Programming
    Replies: 19
    Last Post: 05-03-2008, 05:53 AM
  2. Reverse Engineering on a Download file
    By c_geek in forum C Programming
    Replies: 1
    Last Post: 03-22-2008, 03:15 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Binary file is read with bytes missing
    By thomas41546 in forum C# Programming
    Replies: 1
    Last Post: 09-03-2006, 04:15 AM
  5. Shocking(kind of)
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 12-10-2002, 08:52 PM