List of usage examples for java.net DatagramSocket getReceiveBufferSize
public synchronized int getReceiveBufferSize() throws SocketException
From source file:Main.java
public static void main(String args[]) { try {/*ww w .j a v a 2 s . c o m*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); // Send the datagram packet ds.send(dp); System.out.println(ds.getReceiveBufferSize()); } 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 w w w . j a v a 2 s .c o m*/ }
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 w w w .j a v a 2s. co m*/ } 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; }