List of usage examples for io.netty.channel.udt.nio NioUdtProvider BYTE_CONNECTOR
ChannelFactory BYTE_CONNECTOR
To view the source code for io.netty.channel.udt.nio NioUdtProvider BYTE_CONNECTOR.
Click Source Link
From source file:com.flysoloing.learning.network.netty.udt.echo.bytes.ByteEchoClient.java
License:Apache License
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 {//from w w w .j a v a 2 s. c om 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(); } }
From source file:com.mpush.client.gateway.GatewayClient.java
License:Apache License
@Override public ChannelFactory<? extends Channel> getChannelFactory() { if (CC.mp.net.tcpGateway()) return super.getChannelFactory(); if (CC.mp.net.udtGateway()) return NioUdtProvider.BYTE_CONNECTOR; if (CC.mp.net.sctpGateway()) return NioSctpChannel::new; return super.getChannelFactory(); }
From source file:io.aos.netty5.udt.echo.bytes.ByteEchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the client. final ExecutorServiceFactory connectFactory = new DefaultExecutorServiceFactory("connect"); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER); try {/*from w w w. java 2 s. co m*/ 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(); } }
From source file:org.jupiter.transport.netty.JNettyUdtConnector.java
License:Apache License
@Override protected void doInit() { // child options config().setOption(JOption.SO_REUSEADDR, true); config().setOption(JOption.CONNECT_TIMEOUT_MILLIS, (int) SECONDS.toMillis(3)); // channel factory bootstrap().channelFactory(NioUdtProvider.BYTE_CONNECTOR); }
From source file:se.sics.gvod.net.NettyNetwork.java
License:Open Source License
/** * Connect to a UDT server.//from w w w .j av a 2 s.c o m * * @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; }
From source file:se.sics.kompics.network.netty.NettyNetwork.java
License:Open Source License
public NettyNetwork(NettyInit init) { System.setProperty("java.net.preferIPv4Stack", "true"); self = init.self;//from w ww. j av a 2s . c o m boundPort = self.getPort(); // Prepare Bootstraps bootstrapTCPClient = new Bootstrap(); bootstrapTCPClient.group(new NioEventLoopGroup()).channel(NioSocketChannel.class) .handler(new NettyInitializer<SocketChannel>(new StreamHandler(this, Transport.TCP))) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS) .option(ChannelOption.SO_REUSEADDR, true); bootstrapUDTClient = new Bootstrap(); NioEventLoopGroup groupUDT = new NioEventLoopGroup(1, Executors.defaultThreadFactory(), NioUdtProvider.BYTE_PROVIDER); bootstrapUDTClient.group(groupUDT).channelFactory(NioUdtProvider.BYTE_CONNECTOR) .handler(new NettyInitializer<SocketChannel>(new StreamHandler(this, Transport.UDT))) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS) .option(ChannelOption.SO_REUSEADDR, true); subscribe(startHandler, control); subscribe(stopHandler, control); subscribe(msgHandler, net); subscribe(notifyHandler, net); }