Closing Channels in Netty

이희승 (Trustin Lee) trustin at gmail.com
Tue Aug 25 02:23:00 EDT 2009


On Tue, 25 Aug 2009 12:08:55 +0900 (KST)
Thomas Bocek <bocek at ifi.uzh.ch> wrote:

> Michael McGrady wrote:
> > Here is hopefully an easy question that I have not been doing good  
> > with.  What is the best way to close a channel at both the sender
> > and receiver (client and server) ends?
> 
> Channel.close() will close a TCP channel on the server and client
> side. So you can call close() from either sender or receiver and it
> will close both sides.

To add just a little bit, the side that closes the connection will get
a TIME_WAIT state.  Therefore, it's better for the side with fewer
connections to close the connection to reduce the chance of running
out of ports due to too many TIME_WAIT states. In most case, it's the
client side because the server side often handles much more connections.

HTH,
Trustin


More information about the netty-users mailing list