Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HOW to terminate the thread when the client socket is closed

843790Sep 12 2008 — edited Sep 15 2008
HI,

We are developing a Socket application ,

Server socket will accept the client connections.

For every client connection we will create a thread , this thread will always try to read the messages from the client socket.

here the problem is once the client connection is closed , we are not able to close the thread which is reading the client messages .

because of this , how many number of times the client is disconnected those many threads are unnecessarily running.

we are using socket.isClosed() method , its not helpful , once the connection is closed also it is showing its connected.

after writing some 0 bites to the client socket then only it is giving the exception like client is closed.

[ is there any disadvantage of writing the 0(0x00) bytes to the socket outputstream. ]

and how can i close the thread when the client is disconnected.

i will be very thank full for your reply.

Thanks,
S P K S.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2008
Added on Sep 12 2008
4 comments
1,158 views