简体   繁体   中英

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.

  • See attached pic for example *

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM