List of usage examples for java.net DatagramSocket setSendBufferSize
public synchronized void setSendBufferSize(int size) throws SocketException
From source file:Main.java
public static void main(String args[]) { try {//from w ww . ja v a2 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); ds.setSendBufferSize(1000); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.navercorp.pinpoint.profiler.sender.UdpDataSender.java
private DatagramSocket createSocket(String host, int port, int timeout, int sendBufferSize) { try {/* w w w . j ava 2 s.c o m*/ final DatagramSocket datagramSocket = new DatagramSocket(); datagramSocket.setSoTimeout(timeout); datagramSocket.setSendBufferSize(sendBufferSize); if (logger.isInfoEnabled()) { final int checkSendBufferSize = datagramSocket.getSendBufferSize(); if (sendBufferSize != checkSendBufferSize) { logger.info("DatagramSocket.setSendBufferSize() error. {}!={}", sendBufferSize, checkSendBufferSize); } } final InetSocketAddress serverAddress = new InetSocketAddress(host, port); datagramSocket.connect(serverAddress); return datagramSocket; } catch (SocketException e) { throw new IllegalStateException("DatagramSocket create fail. Cause" + e.getMessage(), 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 w w . j ava2s. co 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 w w w. j a v a 2 s.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; }