bootstrap = new ClientBootstrap(factory);
bootstrap.setOption(
"remoteAddress", new InetSocketAddress(host, port));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
return Channels.pipeline(new SimpleChannelUpstreamHandler()
{
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
{
if (mcast != null && mcast.isInit())
mcast.send((ChannelBuffer) e.getMessage());
}
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) {
timer.schedule(new TimerTask() {
public void run() {
bootstrap.connect();
}
}, RECONNECT_DELAY);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
Throwable cause = e.getCause();
if (cause instanceof ConnectException)
{
System.out.println("conection lost: reconnecting...");
}
ctx.getChannel().close();
}
});
}
});
ChannelFuture f = bootstrap.connect();
channel = f.getChannel();
mcast.init(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
return Channels.pipeline(new SimpleChannelUpstreamHandler()
{
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception