Cannot communicate once bufferedwriter is close in java socket programming -
i made server , client java application. should communicate each other through tcp sockets threads. used inputstreamreader , bufferedreader read message, , used outputstreamwriter , bufferedwriter write message. object of bufferedreader called reader, , object of bufferedwriter called writer.
after playing around that, realized socket becomes irresponsive if writer closed.
i closed writer on server side because never send message, read message client only. not throw exception, stuck called methods relate socket such reader.readline() , socket.setsotimeout().
the problem easy solve since don't close writer. however, curious why socket being unable communicate.
the socket becomes irresponsive if writer closed
the socket becomes closed if writer closed.
i closed writer on server side because never send message,
non sequitur. if don't need writer
, don't construct it.
stuck called methods relate socket such
reader.readline()
,socket.setsotimeout()
.
it isn't 'stuck'. it's closed. must have got socketexception: socket closed
when called either of methods. should have noticed that, , should have posted in question.