Link to home
Start Free TrialLog in
Avatar of Jas001
Jas001

asked on

ChttpFile receives and extra \r in its carriage return

From the server I send 1024 bytes.  On the client I receive 1037 bytes.  When comparing the two files they are identical meaning I received the 1024 bytes.  However, each \r\n in the file is not \r\r\n.  Or in binary 0D 0D 0A.

So, my question is what is adding the extra 0D to the carriage returns?  On the server I its an executable that just passes it down stdout.  I've verified that the data it sends is in fact 1024 bytes.

On the Client I use CHttpFile::Read to get the data and the data has the extra character.

Any ideas?

Regards,
Jas001
Avatar of Jas001
Jas001

ASKER

Sorry:
However, each \r\n in the file is not \r\r\n.
Should be:
However, each \r\n in the file is NOW \r\r\n.
as far as i know soft line breaks (\r\r\n) are only generated by multiline edit controls . is your server using any edit control ?what function do you use on the server to send data ?
Avatar of Jas001

ASKER

I just write it out to stdout like so:
fwrite(buff,sizeof(char),len,stdout);
ASCII transmission mode from a server to a client usually replaces the \n with \r\n, but since the \r\n is already there you get the \r\r\n.

Can you switch to binary mode?
I see you use fwrite.. do you use "b" flag while fopen'ing the file? If not, can you please to add a b (binary) flag next to your "w"... such as:

fopen( filename, "wb+" );
Avatar of Jas001

ASKER

There is no file to open.  Im just writing to standard out like so:
fwrite(buff,sizeof(char),len,stdout);// to standard out.  

The mechanism to send it to the Client is handled by the server via the CHTTP Class.
The input file I'm sending is an ASCII file so I wouldn't want  to open it in binary I don't think.

KurtVon, why would the server parse the file and add a carriage return?  Is there a way to tell the server when I request using CHTTP that I want binary?  And would that mess up my return file since it is ascii and requires the spacing?

I have a fix for the problem by just stripping the extra carriage return out of the data, but I sure would like to know a way around this.
ASKER CERTIFIED SOLUTION
Avatar of Mercantilum
Mercantilum
Flag of Japan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In your question, you are telling us that there is a file containing received data, and you're checking it out, seeing \r\r\n there.. That's why I wanted you to open that file in binary mode. Or, are you using shell redirection > or >> to save the received data?
You say, you receive 1024 bytes from CHttpFile::Read() and you find 1037 bytes in the output file. That means, there is a problem saving this data. Why don't you just open a binary file like we all mentioned above, and write the received data in there using fwrite()? Then check that file size, data in it etc..
Binary mode isn't just for opening binary files.  Ascii mode exists solely so that the operating system knows how to translate the text for proper processing.  As such, it's a bit of a throwback to when systems used different text formats (well, some still do).  Binary format still reads ascii, but it tells the OS (or whatever library is handling the transfer) not to alter the bytes in any way.

I'm afraid I can't be specific because I have no idea what a CHTTP is.  I assume that is the library you are using to make the connection, but I don't know any library where you make a connection with a CHTTP object and then transmit using stdout.
Avatar of Jas001

ASKER

Thanks guys for your comments. I'm going to pick Mercantilum's comment but I wanted to clarify a few things.

Caner elci: There is no file to open in binary mode.  I have to read the data from the CHTTPfile and write the file.  I've stated above that when the data reaches the server there are already characters added to the datastream.  So, I can't open the file in binary, its already been modified.

KurtVon:  CHttp class in MFC is what I'm using.  Its usually used to request a web page or something of that nature and receives a CHttpFile in return.  Instead, I'm requesting an executable which is then run on the server and writes to standardout which will be returned to the CHTTP class as a response.  The data leaving the executable is correct, but the data received by the client has the extra carriage return in it.  

Thanks for your input guys!