Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are no issue with calling channel.write() from different Threads. The read is done by handling events in a custom Handler so there are no multi-threading issue. It is your business to decide what to do when a messageReceived event is fired.</p> <p>The basic way to get the Channel is to use the ClientBootStrap and do that:</p> <pre><code>ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("LOGGER", new LoggingHandler("CLIENT", true)); return pipeline; } }); // Connect to the server, wait for the connection and get back the channel ChannelFuture connectFuture = bootstrap.connect(new InetSocketAddress(host, port)); // Wait until the connection attempt succeeds or fails. Channel channel = connectFuture.awaitUninterruptibly().getChannel(); </code></pre> <p>Another way could be to implement a handler like this and add the handler to the Pipeline in the factory. Then you can access the Channel any time but the first solution seems the best way to do the trick!</p> <pre><code> public class PublicChannelHandler extends SimpleChannelUpstreamHandler { Channel channel; public Channel getChannel(){ if (channel == null) { throw new IllegalStateException("No underlying Channel is associated with this handler at the moment."); } return this.channel; } @Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { this.channel=ctx.getChannel()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload