hawx
hawx

Reputation: 1669

Decoding Data Stream From Socket Connection in Java

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.

enter image description here

Upvotes: 0

Views: 606

Answers (1)

user207421
user207421

Reputation: 310926

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

Upvotes: 1

Related Questions