Skip to content
Marcel Prestel edited this page May 18, 2017 · 2 revisions

Introduction

If you use a websocket connection e.g. for a game and you run into problems keeping the connections to a specific tick rate, you possible run into the Nagle's algorithm causing some delay.

The following examples show how to deactivate this algorithm/enable TCP_NODELAY.

Keep in mind, you can't enable/disable TCP_NODELAY when you initiated the connection already. It only affects new connections.

Enable TCP_NODELAY for the websocket server

To enable TCP_NODELAY for new connections you have to use the setter provided by the WebsocketServer.

E.g. using the example class ChatServer.

ChatServer s = new ChatServer( port );
s.setTcpNoDelay( true );
s.start();

It is recommended to use the setter before you start up the websocket server.

Enable TCP_NODELAY for the websocket client

To enable TCP_NODELAY for the websocket client you have to use the setter provided by the WebsocketClient.

E.g. using the example class ExampleClient.

ExampleClient c = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_6455() );
c.setTcpNoDelay( true );
c.connect();