Reputation: 29703
I have client-server app. Client on C++, server on Java.
I am sending byte-stream form client to server, and from server to client.
Tell me please, when I sent char(-1) from C++, what value equals to it in Java?
And what value I must sent from Java to C++, to get char(-1) in Cpp code?
Upvotes: 0
Views: 189
Reputation: 186068
There's no single answer; it depends on how C++ encodes the data and how Java interprets it. The most common encoding of char(-1)
is the number 255. Note that this isn't defined by C++; a one's-complement system might encode it as 254. But also note that there are innumerable ways to encode data across the wire: Elias coding, various ASN.1 encodings, decimal digits, hex, etc.
At the Java end, even assuming a simple char-to-byte encoding, it depends on how you de-serialise the byte and into what type.
Upvotes: 1
Reputation: 4057
As you are writing through a byte stream, your char(-1)
arrives as 255
, as byte streams normally transmit unsigned bytes.
The -1
which is read when you read the end of a stream can not be send explicitely but only through closing the stream.
Upvotes: 2