Skip to content

Instantly share code, notes, and snippets.

@roooodcastro
Created April 20, 2013 23:33
Show Gist options
  • Save roooodcastro/5427837 to your computer and use it in GitHub Desktop.
Save roooodcastro/5427837 to your computer and use it in GitHub Desktop.
Configuração ClienteTCP
public static int PORTA_CLIENTE_TCP = 1050;
public void iniciarServidorTCP() {
fabrica = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool());
bootstrap = new ServerBootstrap(fabrica);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoderDeMensagem", new MensagemDecoderTCP());
pipeline.addLast("handlerGerente", new GerenteTCP());
pipeline.addLast("encoder de mensagem", new MensagemEncoderTCP());
return pipeline;
}
});
bootstrap.setOption("child.tcpNoDelay", true);
// bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.reuseAddress", true);
// bootstrap.setOption("child.connectTimeoutMillis", 100);
// bootstrap.setOption("readWriteFair", true);
bootstrap.bind(new InetSocketAddress(PORTA_CLIENTE_TCP));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment