8

I am using webSockets to connect a javascript webSocket client to a java webSocketServer (from an Android application), using the Java-WebSocket library. The Android app sends a small message every few milliseconds to the javascript client.

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 ...

This is the effect of the Nagle algorithm, that is set by default, clumping several messages before sending them.

Since I have not found a way to guarantee its deactivation, I follow the approach proposed in this 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.

The question is, this keeps being the best solution to this problem? Do you know any way to avoid the clumping?

Thank you.

asked Oct 15, 2014 at 12:23
6
  • In .NET there is a setting in the socket object to disable the nagle algorithm, probably there is something similar in Java. Commented Oct 15, 2014 at 12:25
  • Is there a .flush() method on the socket you can call after writing to it? Commented Oct 15, 2014 at 19:09
  • 1
    Do you have setTcpNoDelay() available to you in your library? Commented Oct 15, 2014 at 19:31
  • No flush or setTcpNoDelay methods are present in the library. Commented Oct 16, 2014 at 9:30
  • 1
    I did an isolated experiment: github.com/valsteen/socketio-nagle-experiment . Conclusion on chrome for android: acks have no effets. But sending filler packets give great result. It may be an option if you need low latency on a local web-based application. Commented Oct 12, 2015 at 12:46

1 Answer 1

3

Since no flush or setTCPNoDelay mechanisms seem to be present on the used library, and no other solutions have been proposed, it seems that the acknowledge message solution remains valid as the best solution to this problem.

answered Nov 4, 2014 at 12:58
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.