Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

0x0D characters randomly entered between Java Client and Visual C++ Server  RSS feed

 
Tim Anderson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Server that I've written in Visual C++ that will accept socket connections for a variety of message types and deal with them as necessary (that's the definition of a server, right?). My problem is that I have a Java client that is trying to pass a JPEG (actually a JFIF) image to the Server and something's getting lost in the translataion. I've checked on the Java side and it appears that what I'm sending out the Java socket is the correct data.

Here's the Java client side.


The problem is that when my Visual C++ server receives the message from the client, random 0x0D bytes are inserted into the data!

I have tried modifying my code (for test purposes) to see what happens when I just write the data to a file.

and I don't get the spurious 0x0D characters.

This tells me that for some reason, the OutputStream from Socket is sticking in the random 0x0D characters.

Anyone have any ideas??
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

It tells you, more likely, that the Visual C++ runtime system is interpreting the stream of data as text, and adding 0x0D (carraige return) characters after any 0x0A (line feed, in textual data) characters it sees. Make sure the server knows it's supposed to be reading binary data, not text.
 
Tim Anderson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was close to the problem.

Turns out I was opening the file for writing using the default of text-mode (vice binary). So, Visual was happily going along changing my data to suit its needs.

From my Unix c++ days, I could have sworn that the default was to store the data as is.

Thanks for the help
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the default (this is fopen() and FILE *'s we're talking about) is text mode, and you have to use an explicit "b" for binary mode. The kicker, though, is that on UNIX there's zero difference between the two -- doesn't matter which you use. As you can see, though, on Winders there is indeed a difference.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!