title: How to increase send buffer size of a SocketChannel?
body: <p>I've tried to increase the send buffer size of a SocketChannel. I want to send all the bytes in my ByteBuffer in only one write operation. This is my code:</p>
  
  <pre><code>channel = SocketChannel.open(address);
  ByteBuffer buf = ByteBuffer.wrap(channelBytes);
  channel.socket().setSendBufferSize(buf.remaining());
  channel.write(buf);
  </code></pre>
  
  <p>Even if I call the method setSendBufferSize, the socket doesn't send more than 131071 bytes.
  How can I do?</p>
  
  <p>The receiver is this:</p>
  
  <p>Constructor</p>
  
  <pre><code>uplink = ServerSocketChannel.open();
  uplink.socket().bind(new InetSocketAddress(UPLINK_PORT));
  uplink.socket().setReceiveBufferSize(2*1024*1024);
  </code></pre>
  
  <p>Run method</p>
  
  <pre><code>SocketChannel clientChannelUp = uplink.accept();
  clientChannelUp.socket().setReceiveBufferSize(2*1024*1024);
  clientChannelUp.socket().setSendBufferSize(2*1024*1024);
  buffer = ByteBuffer.allocate(Short.MAX_VALUE*100);
  clientChannelUp.read(buffer);
  buffer.flip();
  </code></pre>
  
  <p>With the read and write loop my code is this:</p>
  
  <p>transmitter</p>
  
  <pre><code>while(buf.hasRemaining()) {
      channel.write(buf);
  }
  </code></pre>
  
  <p>receiver</p>
  
  <pre><code>int r = clientChannelUp.read(buffer);
  while(r==131071) {
      r=clientChannelUp.read(buffer);
  }
  buffer.flip();
  </code></pre>