Hi,
I change *a lot* the client parts of the codec tutorial, i keep only two
classes : GraphicalCharGenClient and ImageClient (see below).
I don't understand why the thread called "SocketConnector" doesn't stop
(and so the program doesn't terminate).
Thanks in advance for your response !
Pierre-Louis
*GraphicalCharGenClient.java*
package org.apache.mina.example.imagine.client;
public class GraphicalCharGenClient
{
public static void main(String args[]) throws Exception
{
ImageClient imageClient = new ImageClient("127.0.0.1", 2666);
imageClient.connect();
}
}
*ImageClient.java*
package org.apache.mina.example.imagine.client;
import org.apache.mina.transport.socket.nio.SocketConnector; import
org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.RuntimeIOException;
import java.util.concurrent.*;
import java.net.InetSocketAddress;
import java.util.Hashtable;
import org.apache.mina.common.IdleStatus;
public class ImageClient extends IoHandlerAdapter
{
public static final int CONNECT_TIMEOUT = 3000;
private String host;
private int port;
private SocketConnector connector;
private IoSession session;
private GraphicalCharGenClient imageListener;
public void finalize() throws Throwable
{
super.finalize();
session.close();
}
public ImageClient(String host, int port)
{
this.host = host;
this.port = port;
ExecutorService executor =
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()+1);
connector = new SocketConnector();
connector.getSessionConfig().setTcpNoDelay(true);
ScheduledThreadPoolExecutor scheduler = new
ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
}
public void connect()
{
connector.setHandler(this);
ConnectFuture connectFuture = connector.connect(new
InetSocketAddress(host,port));
if(connectFuture.awaitUninterruptibly(CONNECT_TIMEOUT))
{
session = connectFuture.getSession();
session.setIdleTime(IdleStatus.BOTH_IDLE, 10);
}
}
public void disconnect() {
if (session != null)
{ session = null;
}
}
}