Package io.netty.channel.socket

Examples of io.netty.channel.socket.DatagramChannel


        if (multicastSubnet.getInfo().isInRange(configuration.getHost())) {
            ChannelFuture channelFuture = bootstrap.bind(hostAddress);
            channelFuture.awaitUninterruptibly();
            channel = channelFuture.channel();
            DatagramChannel datagramChannel = (DatagramChannel) channel;
            String networkInterface = configuration.getNetworkInterface() == null ? LOOPBACK_INTERFACE : configuration.getNetworkInterface();
            multicastNetworkInterface = NetworkInterface.getByName(networkInterface);
            ObjectHelper.notNull(multicastNetworkInterface, "No network interface found for '" + networkInterface + "'.");
            LOG.info("ConnectionlessBootstrap joining {}:{} using network interface: {}", new Object[]{configuration.getHost(), configuration.getPort(), multicastNetworkInterface.getName()});
            datagramChannel.joinGroup(hostAddress, multicastNetworkInterface).syncUninterruptibly();
            allChannels.add(datagramChannel);
        } else {
            LOG.info("ConnectionlessBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
            ChannelFuture channelFuture = bootstrap.bind(hostAddress);
            channelFuture.awaitUninterruptibly();
View Full Code Here


        // 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

    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    ByteBufAllocator alloc = mock(ByteBufAllocator.class);
    when(ctx.alloc()).thenReturn(alloc);
    when(alloc.ioBuffer()).thenReturn(buf);

    DatagramChannel dc = mock(DatagramChannel.class);
    when(ctx.channel()).thenReturn(dc);
    when(ctx.writeAndFlush(any(), any(ChannelPromise.class))).thenReturn(
        null);

    Attribute<InetSocketAddress> attr = mock(Attribute.class);
View Full Code Here

        final DnsQuery query = new DnsQuery(id, nameServerAddr);
        query.addQuestion(question);
        query.header().setRecursionDesired(recursionDesired);
        query.addAdditionalResource(optResource);

        final DatagramChannel ch = parent.ch;

        if (logger.isDebugEnabled()) {
            logger.debug("{} WRITE: [{}: {}], {}", ch, id, nameServerAddr, question);
        }

        final ChannelFuture writeFuture = ch.writeAndFlush(query);
        if (writeFuture.isDone()) {
            onQueryWriteCompletion(writeFuture, nameServerAddr);
        } else {
            writeFuture.addListener(new ChannelFutureListener() {
                @Override
View Full Code Here

                            public void channelRead(ChannelHandlerContext ctx, Object msg) {
                                // Discard
                                ReferenceCountUtil.release(msg);
                            }
                        });
                DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap
                        .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
                channelGroup.add(datagramChannel);
            }
            Assert.assertEquals(100, channelGroup.size());
        } finally {
View Full Code Here

            protected void initChannel(DatagramChannel ch) throws Exception {
                ch.pipeline().addLast(DECODER, ENCODER, responseHandler);
            }
        });

        DatagramChannel ch = (DatagramChannel) b.bind(localAddress).channel();
        ch.closeFuture().addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                clearCache();
            }
        });
View Full Code Here

            // No route to host which makes no sense.
            // Maybe a JDK bug ?
            sc.close().awaitUninterruptibly();
            return;
        }
        DatagramChannel cc = (DatagramChannel) cb.bind().sync().channel();

        String group = "230.0.0.1";
        InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort());

        cc.joinGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

        sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
        assertTrue(mhandler.await());

        // leave the group
        cc.leaveGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

        // sleep a second to make sure we left the group
        Thread.sleep(1000);

        // we should not receive a message anymore as we left the group before
        sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
        mhandler.await();

        sc.close().awaitUninterruptibly();
        cc.close().awaitUninterruptibly();
    }
View Full Code Here

TOP

Related Classes of io.netty.channel.socket.DatagramChannel

Copyright © 2018 www.massapicom. 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.