N
nooneinparticular314159
I'm reading data from a socket channel in a network program. To test
my code, I'm telnetting to the program and typing in some data, which
I then try to read from the buffer, view as a charbuffer, and write to
standard out. Unfortunately, what I type in are english letters and
numbers, and what I get out seems to be unicode chinese! Here's what
I'm doing:
try {
NumberOfBytesReadFromChannel = Channel.read
(ReceiveBuffer); //read available data into the buffer
}
ReceiveBuffer.flip(); //flip the buffer so it
can be read
//Read the new data out of the buffer and add it to
IncomingDataString, which stores unprocessed incoming data
IncomingMessageBuffer = ReceiveBuffer.asCharBuffer();
if (IncomingDataString == null) {
IncomingDataString = IncomingMessageBuffer.toString();
} else {
IncomingDataString = IncomingDataString +
IncomingMessageBuffer.toString();
}
//*************************
System.out.println("String received was: " +
IncomingDataString);
ReceiveBuffer.clear();
(Not shown: the IOException catch statement)
What I get are a series of strings that look like:
String received was: 摧æ 摦ഊæœæ æ
So somehow, I seem to be reading the data incorrectly, even though I
am receiving it. Any idea what I'm doing wrong here?
Thanks!
my code, I'm telnetting to the program and typing in some data, which
I then try to read from the buffer, view as a charbuffer, and write to
standard out. Unfortunately, what I type in are english letters and
numbers, and what I get out seems to be unicode chinese! Here's what
I'm doing:
try {
NumberOfBytesReadFromChannel = Channel.read
(ReceiveBuffer); //read available data into the buffer
}
ReceiveBuffer.flip(); //flip the buffer so it
can be read
//Read the new data out of the buffer and add it to
IncomingDataString, which stores unprocessed incoming data
IncomingMessageBuffer = ReceiveBuffer.asCharBuffer();
if (IncomingDataString == null) {
IncomingDataString = IncomingMessageBuffer.toString();
} else {
IncomingDataString = IncomingDataString +
IncomingMessageBuffer.toString();
}
//*************************
System.out.println("String received was: " +
IncomingDataString);
ReceiveBuffer.clear();
(Not shown: the IOException catch statement)
What I get are a series of strings that look like:
String received was: 摧æ 摦ഊæœæ æ
So somehow, I seem to be reading the data incorrectly, even though I
am receiving it. Any idea what I'm doing wrong here?
Thanks!