List of usage examples for java.net DatagramSocket getSendBufferSize
public synchronized int getSendBufferSize() throws SocketException
From source file:Main.java
public static void main(String args[]) { try {/*from ww w . j a va2s . 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.getSendBufferSize()); } 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 {//from w w w . j a v a 2 s . co 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.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 va 2 s. c o 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; }