Examples of NioDatagramChannelFactory


Examples of io.netty.channel.socket.nio.NioDatagramChannelFactory

        this.port = port;
    }

    public void run() {
        DatagramChannelFactory f =
            new NioDatagramChannelFactory(Executors.newCachedThreadPool());

        ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);

        // Configure the pipeline factory.
        b.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(
                        new StringEncoder(CharsetUtil.ISO_8859_1),
                        new StringDecoder(CharsetUtil.ISO_8859_1),
                        new QuoteOfTheMomentClientHandler());
            }
        });

        // Enable broadcast
        b.setOption("broadcast", "true");

        // Allow packets as large as up to 1024 bytes (default is 768).
        // You could increase or decrease this value to avoid truncated packets
        // or to improve memory footprint respectively.
        //
        // Please also note that a large UDP packet might be truncated or
        // dropped by your router no matter how you configured this option.
        // In UDP, a packet is truncated or dropped if it is larger than a
        // certain size, depending on router configuration.  IPv4 routers
        // truncate and IPv6 routers drop a large packet.  That's why it is
        // safe to send small packets in UDP.
        b.setOption(
                "receiveBufferSizePredictorFactory",
                new FixedReceiveBufferSizePredictorFactory(1024));

        DatagramChannel c = (DatagramChannel) b.bind(new InetSocketAddress(0));

        // Broadcast the QOTM request to port 8080.
        c.write("QOTM?", new InetSocketAddress("255.255.255.255", port));

        // QuoteOfTheMomentClientHandler will close the DatagramChannel when a
        // response is received.  If the channel is not closed within 5 seconds,
        // print an error message and quit.
        if (!c.getCloseFuture().awaitUninterruptibly(5000)) {
            System.err.println("QOTM request timed out.");
            c.close().awaitUninterruptibly();
        }

        f.releaseExternalResources();
    }
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    /**
     * {@inheritDoc}
     */
    public void start(int port) throws IOException {
        factory = new NioDatagramChannelFactory();
        ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    @Override
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    /**
     * {@inheritedDoc}
     */
    public void start(final int port, final CountDownLatch counter, final byte[] data) throws IOException {
        factory = new NioDatagramChannelFactory();
        ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
        bootstrap.setOption("sendBufferSize", 65536);
        bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(9000));
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

   * @return open data-gram channel
   */
  private Channel createRtpChannel(final SocketAddress local, final SocketAddress remote, final RaopRtpChannelType channelType)
  {
    /* Create bootstrap helper for a data-gram socket using NIO */
    final ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory(m_rtpExecutorService));
   
    /* Set the buffer size predictor to 1500 bytes to ensure that
     * received packets will fit into the buffer. Packets are
     * truncated if they are larger than that!
     */
 
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    protected void setupUDPCommunication() throws Exception {
        if (datagramChannelFactory == null) {
            int count = configuration.getWorkerCount() > 0 ? configuration.getWorkerCount() : NettyHelper.DEFAULT_IO_THREADS;
            workerPool = new NioDatagramWorkerPool(Executors.newCachedThreadPool(), count);
            datagramChannelFactory = new NioDatagramChannelFactory(workerPool);
        }
    }
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    private static final int SEND_COUNT = 20;
    private int receivedCount;
    private ConnectionlessBootstrap bootstrap;

    public void createNettyUdpReceiver() {
        bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory());
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline channelPipeline = Channels.pipeline();
                channelPipeline.addLast("StringDecoder", new StringDecoder(CharsetUtil.UTF_8));
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    private static final int SEND_COUNT = 20;
    private int receivedCount;
    private ConnectionlessBootstrap bootstrap;

    public void createNettyUdpReceiver() {
        bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory());
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline channelPipeline = Channels.pipeline();
                channelPipeline.addLast("StringDecoder", new StringDecoder(CharsetUtil.UTF_8));
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

 
  public UDPClient(ChannelHandler businessHandler, IAM iam,String remoteHost, int remotePort,ExecutorService executorService)
  {
    this.iam = iam;
    this.serverAddress = new InetSocketAddress(remoteHost,remotePort);
    DatagramChannelFactory f = new NioDatagramChannelFactory(executorService);
    // Create only one bootstrap per instance. But use it to make multiple udp channels.
    b = new ConnectionlessBootstrap(f);
    ChannelPipeline p = b.getPipeline();
    p.addLast("eventDecoder",EVENT_DECODER);
    p.addLast("businessHandler", businessHandler);
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

  @Override
  public Bootstrap createServerBootstrap()
  {
    serverBootstrap = new ConnectionlessBootstrap(
        new NioDatagramChannelFactory(Executors
            .newCachedThreadPool(new NamedThreadFactory(
                "UDP-Server-Worker"))));
    return serverBootstrap;
  }
View Full Code Here

Examples of org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory

    protected void startServerBootstrap() throws UnknownHostException, SocketException {
        // create non-shared worker pool
        int count = configuration.getWorkerCount() > 0 ? configuration.getWorkerCount() : NettyHelper.DEFAULT_IO_THREADS;
        workerPool = new NioDatagramWorkerPool(Executors.newCachedThreadPool(), count);

        datagramChannelFactory = new NioDatagramChannelFactory(workerPool);

        connectionlessBootstrap = new ConnectionlessBootstrap(datagramChannelFactory);
        connectionlessBootstrap.setOption("child.keepAlive", configuration.isKeepAlive());
        connectionlessBootstrap.setOption("child.tcpNoDelay", configuration.isTcpNoDelay());
        connectionlessBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.