List of usage examples for java.net DatagramSocket setReceiveBufferSize
public synchronized void setReceiveBufferSize(int size) throws SocketException
From source file:Main.java
public static void main(String args[]) { try {/*from ww w . ja v a 2 s.com*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setReceiveBufferSize(1000); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.navercorp.pinpoint.collector.receiver.thrift.udp.UDPReceiverTest.java
@Test public void socketBufferSize() throws SocketException { DatagramSocket datagramSocket = new DatagramSocket(); int receiveBufferSize = datagramSocket.getReceiveBufferSize(); logger.debug("{}", receiveBufferSize); datagramSocket.setReceiveBufferSize(64 * 1024 * 10); logger.debug("{}", datagramSocket.getReceiveBufferSize()); datagramSocket.close();//from www. j a va2 s . c o m }
From source file:cai.flow.collector.Collector.java
/** * * @throws Throwable/*from w w w . j ava 2 s .c o m*/ */ public void reader_loop() throws Throwable { DatagramSocket socket; try { try { socket = new DatagramSocket(localPort, localHost); socket.setReceiveBufferSize(receiveBufferSize); } catch (IOException exc) { logger.fatal("Reader - socket create error: " + localHost + ":" + localPort); logger.debug(exc); throw exc; } while (true) { byte[] buf = new byte[2048];// DatagramPacket p = null; if (p == null) { p = new DatagramPacket(buf, buf.length); try { socket.receive(p); } catch (IOException exc) { logger.error("Reader - socket read error: " + exc.getMessage()); logger.debug(exc); put_to_queue(null);// notifyAll break; } } if (this.sampler.shouldDue()) { put_to_queue(p); } p = null; } } catch (Throwable e) { logger.error("Exception trying to abort collector"); put_to_queue(null); throw e; } }
From source file:org.limewire.mojito.io.MessageDispatcherImpl.java
@Override public void bind(SocketAddress address) throws IOException { synchronized (lock) { if (isBound()) { throw new IOException("DatagramChannel is already bound"); }// w ww.j av a2s .c o m channel = DatagramChannel.open(); channel.configureBlocking(false); selector = Selector.open(); channel.register(selector, SelectionKey.OP_READ); DatagramSocket socket = channel.socket(); socket.setReuseAddress(false); socket.setReceiveBufferSize(RECEIVE_BUFFER_SIZE); socket.setSendBufferSize(SEND_BUFFER_SIZE); socket.bind(address); } }
From source file:org.mule.transport.udp.UdpSocketFactory.java
public Object makeObject(Object key) throws Exception { ImmutableEndpoint ep = (ImmutableEndpoint) key; DatagramSocket socket; if (ep instanceof InboundEndpoint) { int port = ep.getEndpointURI().getPort(); String host = ep.getEndpointURI().getHost(); if (port > 0) { if ("null".equalsIgnoreCase(host)) { socket = createSocket(port); } else { socket = createSocket(port, InetAddress.getByName(host)); }//from ww w. j a v a2 s . com } else { socket = createSocket(); } } else { //If this is a client socket create a default instance socket = createSocket(); } UdpConnector connector = (UdpConnector) ep.getConnector(); //There is some overhead in stting socket timeout and buffer size, so we're //careful here only to set if needed if (connector.getReceiveBufferSize() != Connector.INT_VALUE_NOT_SET && socket.getReceiveBufferSize() != connector.getReceiveBufferSize()) { socket.setReceiveBufferSize(connector.getReceiveBufferSize()); } if (connector.getSendBufferSize() != Connector.INT_VALUE_NOT_SET && socket.getSendBufferSize() != connector.getSendBufferSize()) { socket.setSendBufferSize(connector.getSendBufferSize()); } if (connector.getTimeout() != Connector.INT_VALUE_NOT_SET && socket.getSoTimeout() != connector.getTimeout()) { socket.setSoTimeout(connector.getTimeout()); } socket.setBroadcast(connector.isBroadcast()); return socket; }