Нужно подключиться к серверу и отправлять данные. Ответы от сервера обрабатывать не нужно. После подключения сразу же происходит дисконнект.
Код | ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("time", new TimeClientHandler()); return pipeline; } }); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); //bootstrap.setOption("remoteAddress", new InetSocketAddress(server, Integer.parseInt(port))); ChannelFuture future = bootstrap.connect(new InetSocketAddress(server, Integer.parseInt(port))); Log.info("Retransalte connection Host: " + server + " port: " + port); channel = future.getChannel(); //future.awaitUninterruptibly().getChannel(); //channel = future.awaitUninterruptibly().getChannel(); if (!future.isSuccess()) { Log.info("Disconnected by client"); // после подключения сразу же отключается bootstrap.releaseExternalResources(); return; } channel.getCloseFuture().awaitUninterruptibly();
|
|