Tadagat K
Tadagat K

Reputation: 41

How to close the socket from client side?

I have a server and client developed using netty. On the client side after writing couple of messages using same channel, I try to close the socket (release resources). I have followed the instructions @ http://netty.io/docs/unstable/guide/html/#start.12

After doing the steps mentioned also, the client is still not shut down.

Can any one of the netty experts help me here.

Regards T

Upvotes: 0

Views: 318

Answers (2)

Renaud
Renaud

Reputation: 2129

I am doing this in my code:

public class TimeClient {
  public static void main(String[] args) throws Exception {
        ...
      ChannelFactory factory = ...;
        ClientBootstrap bootstrap = ...;
      ...
        ChannelFuture future(29) = bootstrap.connect(...);
      future.awaitUninterruptibly();(30)
        if (!future.isSuccess()) {
          future.getCause().printStackTrace();(31)
        }
      ... YOUR BUSINESS LOGIC HERE
      future.getChannel().close().awaitUninterruptibly();(32)
        factory.releaseExternalResources();(33)
  }
}

Upvotes: 0

jtahlborn
jtahlborn

Reputation: 53694

that code seems to be missing the call to actually close the channel. i believe you want to actually call Channel.close() before line 14.

Upvotes: 1

Related Questions