0

I have the code below to read from my socket connection.

String line = null;
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while((line = reader.readLine())!=null){
                System.out.println(line);
            }
            reader.close();
        }catch(IOException e){
}

I can successfully connect to it using a TCP client, but when I try and send a message in Hex I am getting unrecognisable characters in return.

I am suspecting I need to convert to ASCII, but how would this be done.

Any help would be appreciated.

  • See attached pic for example *

enter image description here

2
  • Define 'send a message in hex'. Define 'unrecognizable characters'. It sounds like you are sending binary, in which case you shouldn't be using a Reader, or reading lines, at all. Commented Jan 27, 2014 at 22:17
  • I have attached a screen shot. Hope that helps :-) Commented Jan 27, 2014 at 22:32

1 Answer 1

1

Readers and Writers are for text. Use the input and output streams directly, or via a BufferedOutputStream with appropriate flushing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.