Java Code Examples for org.jboss.netty.bootstrap.ConnectionlessBootstrap#bind()
The following examples show how to use
org.jboss.netty.bootstrap.ConnectionlessBootstrap#bind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UdpServer.java From feeyo-hlsserver with Apache License 2.0 | 6 votes |
public void startup(int port) { ChannelFactory channelFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool()); bootstrap = new ConnectionlessBootstrap( channelFactory ); bootstrap.setOption("reuseAddress", false); bootstrap.setOption("child.reuseAddress", false); bootstrap.setOption("readBufferSize", 1024 * 1024 * 15); //15M bootstrap.setOption("writeBufferSize", 1024 * 20); bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(1024 * 3)); bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(1024 * 3)); bootstrap.setPipelineFactory( new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("handler", new UdpServerChannelHandler()); return pipeline; } }); datagramChannel = (DatagramChannel) bootstrap.bind( new InetSocketAddress( port ) ); }
Example 2
Source File: SimpleUdpServer.java From hadoop with Apache License 2.0 | 6 votes |
public void run() { // Configure the client. DatagramChannelFactory f = new NioDatagramChannelFactory( Executors.newCachedThreadPool(), workerCount); server = new ConnectionlessBootstrap(f); server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE)); server.setOption("broadcast", "false"); server.setOption("sendBufferSize", SEND_BUFFER_SIZE); server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE); // Listen to the UDP port ch = server.bind(new InetSocketAddress(port)); InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress(); boundPort = socketAddr.getPort(); LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount); }
Example 3
Source File: SimpleUdpServer.java From big-c with Apache License 2.0 | 6 votes |
public void run() { // Configure the client. DatagramChannelFactory f = new NioDatagramChannelFactory( Executors.newCachedThreadPool(), workerCount); server = new ConnectionlessBootstrap(f); server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE)); server.setOption("broadcast", "false"); server.setOption("sendBufferSize", SEND_BUFFER_SIZE); server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE); // Listen to the UDP port ch = server.bind(new InetSocketAddress(port)); InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress(); boundPort = socketAddr.getPort(); LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount); }
Example 4
Source File: SyslogUDPSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public void start() { // setup Netty server ConnectionlessBootstrap serverBootstrap = new ConnectionlessBootstrap (new OioDatagramChannelFactory(Executors.newCachedThreadPool())); final syslogHandler handler = new syslogHandler(); handler.setFormater(formaterProp); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { return Channels.pipeline(handler); } }); if (host == null) { nettyChannel = serverBootstrap.bind(new InetSocketAddress(port)); } else { nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port)); } super.start(); }
Example 5
Source File: UdpClient.java From feeyo-hlsserver with Apache License 2.0 | 5 votes |
public UdpClient(final UdpClientChannelHandler channelHandler) { bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory()); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("handler", channelHandler); return pipeline; } }); bootstrap.setOption("localAddress", new InetSocketAddress(10002)); channel = bootstrap.bind(); }
Example 6
Source File: Portmap.java From hadoop with Apache License 2.0 | 5 votes |
void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) { tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); tcpServer.setPipelineFactory(new ChannelPipelineFactory() { private final HashedWheelTimer timer = new HashedWheelTimer(); private final IdleStateHandler idleStateHandler = new IdleStateHandler( timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS); @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler, RpcUtil.STAGE_RPC_TCP_RESPONSE); } }); udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory( Executors.newCachedThreadPool())); udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE)); tcpChannel = tcpServer.bind(tcpAddress); udpChannel = udpServer.bind(udpAddress); allChannels.add(tcpChannel); allChannels.add(udpChannel); LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress() + ", udp://" + udpChannel.getLocalAddress()); }
Example 7
Source File: Portmap.java From big-c with Apache License 2.0 | 5 votes |
void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) { tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); tcpServer.setPipelineFactory(new ChannelPipelineFactory() { private final HashedWheelTimer timer = new HashedWheelTimer(); private final IdleStateHandler idleStateHandler = new IdleStateHandler( timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS); @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler, RpcUtil.STAGE_RPC_TCP_RESPONSE); } }); udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory( Executors.newCachedThreadPool())); udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE)); tcpChannel = tcpServer.bind(tcpAddress); udpChannel = udpServer.bind(udpAddress); allChannels.add(tcpChannel); allChannels.add(udpChannel); LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress() + ", udp://" + udpChannel.getLocalAddress()); }
Example 8
Source File: CarbonTextServer.java From kairos-carbon with Apache License 2.0 | 5 votes |
@Override public void start() throws KairosDBException { // Configure the server. m_serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Configure the pipeline factory. m_serverBootstrap.setPipelineFactory(this); m_serverBootstrap.setOption("child.tcpNoDelay", true); m_serverBootstrap.setOption("child.keepAlive", true); m_serverBootstrap.setOption("reuseAddress", true); // Bind and start to accept incoming connections. m_serverBootstrap.bind(new InetSocketAddress(m_address, m_port)); m_udpBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory()); m_udpBootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(m_maxSize)); m_udpBootstrap.setPipelineFactory(this); m_udpBootstrap.bind(new InetSocketAddress(m_port)); }
Example 9
Source File: CarbonPickleServer.java From kairos-carbon with Apache License 2.0 | 5 votes |
@Override public void start() throws KairosDBException { // Configure the server. m_serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Configure the pipeline factory. m_serverBootstrap.setPipelineFactory(this); m_serverBootstrap.setOption("child.tcpNoDelay", true); m_serverBootstrap.setOption("child.keepAlive", true); m_serverBootstrap.setOption("reuseAddress", true); // Bind and start to accept incoming connections. m_serverBootstrap.bind(new InetSocketAddress(m_address, m_port)); m_udpBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory()); m_udpBootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(m_maxSize)); m_udpBootstrap.setPipelineFactory(this); m_udpBootstrap.bind(new InetSocketAddress(m_port)); }
Example 10
Source File: NettyUdpReceiverTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void server() throws IOException, InterruptedException { final ConnectionlessBootstrap udpServer = createUdpServer(); Thread thread = new Thread(new Runnable() { @Override public void run() { udpServer.bind(new InetSocketAddress("127.0.0.1", PORT)); try { logger.debug("server-await"); latch.await(); } catch (InterruptedException ignored) { } logger.debug("server-shutdown"); udpServer.shutdown(); } }); thread.start(); Thread.sleep(1000); logger.debug("start--------"); // ExecutorService executorService = Executors.newFixedThreadPool(10); // for (int i =0; i< 10; i++) { // executorService.execute(new Runnable() { // @Override // public void run() { // try { start(); // } catch (IOException e) { // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. // } // } // }); // } // executorService.awaitTermination(120, TimeUnit.SECONDS) ; latch.countDown(); }
Example 11
Source File: RaopAudioHandler.java From Android-Airplay-Server with MIT License | 4 votes |
/** * Creates an UDP socket and handler pipeline for RTP channels * * @param local local end-point address * @param remote remote end-point address * @param channelType channel type. Determines which handlers are put into the pipeline * @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(rtpExecutorService)); final ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(new OioDatagramChannelFactory(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! */ bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(1500)); /* Set the socket's receive buffer size. We set it to 1MB */ bootstrap.setOption("receiveBufferSize", 1024 * 1024); /* Set pipeline factory for the RTP channel */ bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { final ChannelPipeline pipeline = Channels.pipeline(); final AirPlayServer airPlayServer = AirPlayServer.getIstance(); pipeline.addLast("executionHandler", airPlayServer.getChannelExecutionHandler()); pipeline.addLast("exceptionLogger", exceptionLoggingHandler); pipeline.addLast("decoder", decodeHandler); pipeline.addLast("encoder", encodeHandler); /* We pretend that all communication takes place on the audio channel, * and simply re-route packets from and to the control and timing channels */ if ( ! channelType.equals(RaopRtpChannelType.Audio)) { pipeline.addLast("inputToAudioRouter", inputToAudioRouterDownstreamHandler); /* Must come *after* the router, otherwise incoming packets are logged twice */ pipeline.addLast("packetLogger", packetLoggingHandler); } else { /* Must come *before* the router, otherwise outgoing packets are logged twice */ pipeline.addLast("packetLogger", packetLoggingHandler); pipeline.addLast("audioToOutputRouter", audioToOutputRouterUpstreamHandler); pipeline.addLast("timing", timingHandler); pipeline.addLast("resendRequester", resendRequestHandler); if (decryptionHandler != null){ pipeline.addLast("decrypt", decryptionHandler); } if (audioDecodeHandler != null){ pipeline.addLast("audioDecode", audioDecodeHandler); } pipeline.addLast("enqueue", audioEnqueueHandler); } return pipeline; } }); Channel channel = null; boolean didThrow = true; try { /* Bind to local address */ channel = bootstrap.bind(local); /* Add to group of RTP channels beloging to this RTSP connection */ rtpChannels.add(channel); /* Connect to remote address if one was provided */ if (remote != null){ channel.connect(remote); } didThrow = false; return channel; } finally { if (didThrow && (channel != null)){ channel.close(); } } }