[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ChttpFile receives and extra \r in its carriage return

Posted on 2004-04-14
10
Medium Priority
?
630 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:Jas001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 2

Author Comment

by:Jas001
ID: 10826415
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.
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10827497
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 ?
0
 
LVL 2

Author Comment

by:Jas001
ID: 10827604
I just write it out to stdout like so:
fwrite(buff,sizeof(char),len,stdout);
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 11

Expert Comment

by:KurtVon
ID: 10827656
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?
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10827703
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+" );
0
 
LVL 2

Author Comment

by:Jas001
ID: 10828459
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.
0
 
LVL 10

Accepted Solution

by:
Mercantilum earned 2000 total points
ID: 10829044
I guess your server is Windows based.

Try this before calling fwrite.

    #include <io.h>
    #include <fcntl.h>

   /* Set "stdout" to have binary mode */
   int result;

   result = _setmode( _fileno( stdout ), _O_BINARY );
   if( result == -1 )
      perror( "Cannot set mode" );
   else
      printf( "'stdin' successfully changed to binary mode\n" );

From the help of VC++ 6.

(  If it does not work, you can try using  freopen, using "con" as a file name (windows) or "/dev/tty" (unix/linux), with "wb" attribute.  )

Regards
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10830838
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..
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 10833547
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.
0
 
LVL 2

Author Comment

by:Jas001
ID: 10861254
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!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question