I have a Socket that works well, but is it possible to write a newline to the Socket OutputStream?
This is what I’ve tried:
InputStream input = clientSocket.getInputStream();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
out.write("Hello" + "\r\n");
out.write("People");
out.flush();
“newline” is a text-based concept. An
OutputStreamis a binary-based concept.If you’re writing text to the socket, you should use a
Writerof some description, e.g. anOutputStreamWriter. You can then wrap that in aBufferedWriterwhich has an appropriatenewLine()method.If you’re not writing text to the socket, then “new line” doesn’t really make much sense.