当前位置: 首页>>代码示例>>Java>>正文


Java UdtChannel类代码示例

本文整理汇总了Java中io.netty.channel.udt.UdtChannel的典型用法代码示例。如果您正苦于以下问题:Java UdtChannel类的具体用法?Java UdtChannel怎么用?Java UdtChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UdtChannel类属于io.netty.channel.udt包,在下文中一共展示了UdtChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:ByteEchoPeerBase.java

示例2: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    final ThreadFactory connectFactory = new UtilThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:23,代码来源:ByteEchoPeerBase.java

示例3: main

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        // Configure the client.
        final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
        final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
                connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
        try {
            final Bootstrap boot = new Bootstrap();
            boot.group(connectGroup)
                    .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
                    .handler(new ChannelInitializer<UdtChannel>() {
                        @Override
                        public void initChannel(final UdtChannel ch)
                                throws Exception {
                            ch.pipeline().addLast(
                                    new LoggingHandler(LogLevel.INFO),
                                    new MsgEchoClientHandler());
                        }
                    });
            // Start the client.
            final ChannelFuture f = boot.connect(HOST, PORT).sync();
            // Wait until the connection is closed.
            f.channel().closeFuture().sync();
        } finally {
            // Shut down the event loop to terminate all threads.
            connectGroup.shutdownGracefully();
        }
    }
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:29,代码来源:MsgEchoClient.java

示例4: main

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    final ThreadFactory acceptFactory = new DefaultThreadFactory("accept");
    final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
    final NioEventLoopGroup acceptGroup =
            new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.MESSAGE_PROVIDER);
    final NioEventLoopGroup connectGroup =
            new NioEventLoopGroup(1, connectFactory, NioUdtProvider.MESSAGE_PROVIDER);

    // Configure the server.
    try {
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(PORT).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:35,代码来源:MsgEchoServer.java

示例5: main

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // Configure the client.
    final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoClientHandler());
                    }
                });
        // Start the client.
        final ChannelFuture f = boot.connect(HOST, PORT).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:28,代码来源:ByteEchoClient.java

示例6: main

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    final ThreadFactory acceptFactory = new DefaultThreadFactory("accept");
    final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.BYTE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER);

    // Configure the server.
    try {
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup)
                .channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(PORT).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:33,代码来源:ByteEchoServer.java

示例7: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    // Configure the peer.
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoPeerHandler(messageSize));
                    }
                });
        // Start the peer.
        final ChannelFuture f = boot.connect(peer, self).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:28,代码来源:MsgEchoPeerBase.java

示例8: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
@Override
public void run() {
    final Bootstrap boot = new Bootstrap();
    final ThreadFactory clientFactory = new DefaultThreadFactory("client");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            clientFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {

                    @Override
                    protected void initChannel(final UdtChannel ch)
                            throws Exception {
                        final ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast("framer",
                                new DelimiterBasedFrameDecoder(8192,
                                        Delimiters.lineDelimiter()));
                        pipeline.addLast("decoder", new StringDecoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("encoder", new StringEncoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("handler", new ClientHandler());
                    }
                });
        channel = boot.connect(host, port).sync().channel();
        isRunning = true;
        log.info("Client ready.");
        waitForRunning(false);
        log.info("Client closing...");
        channel.close().sync();
        isShutdown = true;
        log.info("Client is done.");
    } catch (final Throwable e) {
        log.error("Client failed.", e);
    } finally {
        connectGroup.shutdownGracefully().syncUninterruptibly();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:40,代码来源:UDTClientServerConnectionTest.java

示例9: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    // Configure the client.
    final ThreadFactory connectFactory = new UtilThreadFactory("connect");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoClientHandler(messageSize));
                    }
                });
        // Start the client.
        final ChannelFuture f = boot.connect(host, port).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:28,代码来源:MsgEchoClient.java

示例10: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    final ThreadFactory acceptFactory = new UtilThreadFactory("accept");
    final ThreadFactory connectFactory = new UtilThreadFactory("connect");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
            acceptFactory, NioUdtProvider.MESSAGE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    // Configure the server.
    try {
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(port).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:34,代码来源:MsgEchoServer.java

示例11: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    // Configure the client.
    final ThreadFactory connectFactory = new UtilThreadFactory("connect");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoClientHandler(messageSize));
                    }
                });
        // Start the client.
        final ChannelFuture f = boot.connect(host, port).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:28,代码来源:ByteEchoClient.java

示例12: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    final ThreadFactory acceptFactory = new UtilThreadFactory("accept");
    final ThreadFactory connectFactory = new UtilThreadFactory("connect");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
            acceptFactory, NioUdtProvider.BYTE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    // Configure the server.
    try {
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup)
                .channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(port).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:34,代码来源:ByteEchoServer.java

示例13: run

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
public void run() throws Exception {
    // Configure the peer.
    final ThreadFactory connectFactory = new UtilThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoPeerHandler(messageSize));
                    }
                });
        // Start the peer.
        final ChannelFuture f = boot.connect(peer, self).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:28,代码来源:MsgEchoPeerBase.java

示例14: bindUdtPort

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
/**
 * Start listening as a server at the given address..
 *
 * @param addr the address to listen at
 * @param port the port number to listen at
 * @param bindAllNetworkIfs whether to bind on all network interfaces
 * @return true if listening was started
 * @throws ChannelException in case binding failed
 */
private boolean bindUdtPort(InetAddress addr, int port, boolean bindAllNetworkIfs) {

    if (udtPortsToSockets.containsKey(port)) {
        return true;
    }

    ThreadFactory bossFactory = new UtilThreadFactory("boss");
    ThreadFactory workerFactory = new UtilThreadFactory("worker");
    NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, bossFactory,
            NioUdtProvider.BYTE_PROVIDER);
    NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory,
            NioUdtProvider.BYTE_PROVIDER);
    NettyUdtServerHandler handler = new NettyUdtServerHandler(component);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
            .childHandler(new NettyInitializer<UdtChannel>(handler, msgDecoderClass))
            .option(ChannelOption.SO_REUSEADDR, true);

    try {
        if (bindAllNetworkIfs) {
            bootstrap.bind(new InetSocketAddress(port)).sync();
        } else {
            bootstrap.bind(new InetSocketAddress(addr, port)).sync();
        }

        logger.debug("Successfully bound to ip:port {}:{}", addr, port);
    } catch (InterruptedException e) {
        logger.warn("Problem when trying to bind to {}:{}", addr.getHostAddress(), port);
        trigger(new Fault(e.getCause()), control);
        return false;
    }

    InetSocketAddress iAddr = new InetSocketAddress(addr, port);
    udtPortsToSockets.put(port, iAddr);
    udtSocketsToServerBootstraps.put(iAddr, bootstrap);

    return true;
}
 
开发者ID:jimdowling,项目名称:nat-traverser,代码行数:48,代码来源:NettyNetwork.java

示例15: connectUdt

import io.netty.channel.udt.UdtChannel; //导入依赖的package包/类
/**
 * Connect to a UDT server.
 *
 * @param remoteAddress the remote address
 * @param localAddress the local address to bind to
 * @return true if connection succeeded
 * @throws ChannelException if connecting failed
 */
private boolean connectUdt(Address remoteAddress, Address localAddress) {
    InetSocketAddress remote = address2SocketAddress(remoteAddress);
    InetSocketAddress local = address2SocketAddress(localAddress);

    if (udtSocketsToBootstraps.containsKey(remote)) {
        return true;
    }

    ThreadFactory workerFactory = new UtilThreadFactory("clientWorker");
    NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory,
            NioUdtProvider.BYTE_PROVIDER);
    NettyStreamHandler handler = new NettyStreamHandler(component, Transport.UDT);
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(workerGroup).channelFactory(NioUdtProvider.BYTE_CONNECTOR)
            .handler(new NettyInitializer<UdtChannel>(handler, msgDecoderClass))
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS)
            .option(ChannelOption.SO_REUSEADDR, true);

    try {
        UdtChannel c = (UdtChannel) bootstrap.connect(remote, local).sync().channel();
        addLocalSocket(remote, c);
        logger.debug("Successfully connected to ip:port {}", remote.toString());
    } catch (InterruptedException e) {
        logger.warn("Problem when trying to connect to {}", remote.toString());
        trigger(new Fault(e.getCause()), control);
        return false;
    }

    udtSocketsToBootstraps.put(remote, bootstrap);
    return true;
}
 
开发者ID:jimdowling,项目名称:nat-traverser,代码行数:40,代码来源:NettyNetwork.java


注:本文中的io.netty.channel.udt.UdtChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。