title: Best way to avoid Nagle algorithm effects using webSockets?
body: <p>I am using webSockets to connect a javascript webSocket client to a java webSocketServer (from an Android application), using the <a href="https://github.com/TooTallNate/Java-WebSocket" rel="nofollow noreferrer">Java-WebSocket</a> library. The Android app sends a small message every few milliseconds to the javascript client.</p>
  
  <p>Using the basic (and intuitive) approach for this situation, the delay between received messages, measured inside the javascript Client show (aproximately) the following pattern:
  200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms ...</p>
  
  <p>This is the effect of the Nagle algorithm, that is set by default, clumping several messages before sending them.</p>
  
  <p>Since I have not found a way to guarantee its deactivation, I follow the approach proposed in <a href="https://stackoverflow.com/questions/13373519/websocket-tcp-packets-clumping-together/13406438#13406438">this</a> old question, sending an acknowledge message from the client to the server, and the system behaves properly, but since the acknowledge message has no real purpose (it is more a hack), it should be avoided.</p>
  
  <p>The question is, this keeps being the best solution to this problem? Do you know any way to avoid the clumping?</p>
  
  <p>Thank you.</p>