Skip to content

Instantly share code, notes, and snippets.

@nickman
Created May 18, 2012 00:41
Show Gist options
  • Select an option

  • Save nickman/2722474 to your computer and use it in GitHub Desktop.

Select an option

Save nickman/2722474 to your computer and use it in GitHub Desktop.
Simple Channel Factory
Executor bossPool = Executors.newCachedThreadPool();
Executor workerPool = Executors.newCachedThreadPool();
ChannelFactory channelFactory = new NioClientSocketChannelFactory(boosPool, workerPool);
ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
new ObjectEncoder()
}
};
Bootstrap boostrap = new ClientBootstrap(channelFactory);
boostrap.setPipelineFactory(pipelineFactory);
// Phew. Ok. We built all that. Now what ?
InetSocketAddress addressToConnectTo = new InetSocketAddress(remoteHost, remotePort);
bootstrap.connect(addressToConnectTo);
// Alright ! Now we're done, but remeber, that connect call is asynchronous
// so if this line was code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment