Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Unreadable Hexadecimal Character With Socket

  Asked By: Kaua    Date: Jul 07    Category: Java    Views: 1498
  

I try to catch message from my client over socket. the message contains
text and character hexadecimal, ex: chr(1C), chr(1D). Everytime my
client send the message, i never accepted, but when my client close the
socket, all the message appear in my server program. It seems like the
message been hold in stack memory or something, i don't know.
the code in server side is:

BufferedReader inFromClient;
DataOutputStream outToClient;
String dataFromClient;
try {
inFromClient=new BufferedReader(new
InputStreamReader(serverSocket.getInputStream()));
boolean isQuit=false;
while (!isQuit) {
dataFromClient=inFromClient.readLine();
System.out.println(dataFromClient);
}
inFromClient.close();
serverSocket.close();
}
catch(IOException ioe) {
System.out.println("error: " + ioe);
}

where do i wrong?, please help me.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Janelle Evans     Answered On: Jul 07

as far as I know (I've never used it yet) the method readLine() reads
data up to the next end-of-line character. So if you're dealing with
binary coded data you simply can't assume that any string  will be
delimited by an end-of-line character  (such as LF, 0x0a, on Unix and
CR/LF, 0x0d+0x0a, on Windows).
Stick to reading the data in binary mode, there's probably no other
way. Try to determine for your particular transport protocol how
strings are encoded; I bet they are not terminated by newline
characters.

 
Didn't find what you were looking for? Find more on Unreadable Hexadecimal Character With Socket Or get search suggestion and latest updates.