• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to terminate NIO Server Connection?  RSS feed

 
Abdullah Ahmed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I have really problem, i try to terminate the server connection from listing on specific port but it is still listing and i get these exceptions when i close the connection.

i am using JDK1.6.

Close Connection code:


Exceptions when Close Connection:


I desperately need help.

thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I read the JavaDocs for java.nio.channels.ClosedChannelException, this indicates that "an attempt is made to invoke or complete an IO operation upon a channel that is closed or at least closed to that operation."

Are there other Threads that may be using this port?

Bill
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not at all surprising that "accept" would throw an exception if you close the socket channel it's trying to use -- sounds like expected behavior. Either wrap your calls to accept() in a try/catch block to handle shutdown, or don't shut down the socket while accept() is running -- and of course don't call accept() again after the socket has been closed!
 
Abdullah Ahmed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,

first thanks for your answer, yes there are another thread working but i do not know if it uses the same port.

I am using this sample code (only the server code) from this web site Click here

Thanks bill.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!