Le 5/13/13 7:44 PM, Whitener, Winona T. a écrit :
> My client class:
>
> public class Client {
> private NioSocketConnector connector;
> private ConnectFuture connectFuture;
> private IoSession ioSession;
> private ClientHandler clientHandler;
>
> public Client(final String address, final int port) {
> try {
> connector = new NioSocketConnector();
> connector.getSessionConfig().setReadBufferSize(4096);
> connector.getSessionConfig().setTcpNoDelay(true);
> LoggingFilter loggingFilter = new LoggingFilter();
> connector.getFilterChain().addLast("logging",
> loggingFilter);
> connector.getFailterChain().addLast("codec", new
> ProtocolCodecFilter(new customProtocolCodecFactory()));
>
> clientHandler = new ClientHandler(this);
> connector.setHandler(clientHandler);
>
> createConnection(address, port);
> }
> catch (Exception e) {
> e.printStackTrace();
> //handling logging
> }
>
> public void writeMessage(String message) {
> ioSession.write(message);
> }
>
> private void createConnection(string address, int port) throws
> InterruptedException {
> for (;;) {
> try {
> connectFuture = connector.connect(new
> InetSocketAddress(address, port));
> connectFuture.join();
> ioSession = connectFuture.getSession();
> break;
> }
> catch (Exception e) {
> //handling of error and attempt to reconnect
> }
> }
>
> public void close() {
> //this doesn't get called inappropriately
> connectFuture.getSession().close(true);
> connectFuture.awaitUninterruptibly();
> connector.dispose();
> }
> }
Nothing bad here. What about the handler ?
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com