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();
}
}
-----Original Message-----
From: Emmanuel Lécharny [mailto:[email protected]]
Sent: Monday, May 13, 2013 1:14 PM
To: [email protected]
Subject: Re: Help with NioSocketConnector
Le 5/13/13 6:16 PM, Whitener, Winona T. a écrit :
> More information:
>
> In my latest test run, the encoder/decoder did work successfully. They
> parsed out my start of message and end of message characters correctly. They
> are applied to both the acceptor and connector. The messages going to and
> from the acceptor both are applied correctly. There is no idle timeout
> applied to either end. No exceptions are caught at either end. I have seen
> exceptions while attempting to initially set up the encoder/decoder and those
> were caught--so I know that the exception handling on both ends is there and
> catches exceptions.
So assuming the codec is working, that no exception is thrown, there must be
something wrong with the way you use the connector.
Keep in mind that this is an asynchronous framework, ie any call you make
(write, for instance) will not block.
It's hard to know what's wrong n your code without seing it...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com