Can you have an PrintWriter and ObjectOutputStream on the same sockets output stream?
out_stream = new PrintWriter(socket.getOutputStream(), true);
obj_stream = new ObjectOutputStream(socket.getOutputStream();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can but you have to take care of buffering. A
PrintWriteror anObjectOutputStreamaccepts data, which it converts into bytes, to be sent on the underlying stream (here the socket) at some point. Buffering is about waiting a bit before writing out such bytes, so that the bytes can be sent in “big chunks” rather than individually.Read the Javadoc about buffering, and use
flush()onPrintWriterandObjectOutputStreamwhen you want to get sure that the bytes get written on the socket.