F
F
fsfsfs322020-09-18 10:10:04
Java
fsfsfs32, 2020-09-18 10:10:04

How to read bytes from a socket into a buffer in java and then display it on the screen?

My code:

Socket s = new Socket(host, Integer.parseInt(port));

        PrintWriter out = new PrintWriter(s.getOutputStream(),true);
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

        out.println("tyda"); 

        char[] buff = new char[1024];
        in.read(buff,0,buff.length);

        System.out.println(buff);


Doesn't work, as you can see. how to output this buffer to stdout to read the response?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question