@@ -88,6 +88,11 @@ public abstract class WebSocketServer extends WebSocketAdapter implements Runnab
8888
8989 private WebSocketServerFactory wsf = new DefaultWebSocketServerFactory ();
9090
91+ /**
92+ * Attribute which allows you to deactivate the Nagle's algorithm
93+ */
94+ private boolean tcpNoDelay ;
95+
9196 /**
9297 * Creates a WebSocketServer that will attempt to
9398 * listen on port <var>WebSocket.DEFAULT_PORT</var>.
@@ -181,7 +186,7 @@ public WebSocketServer( InetSocketAddress address , int decodercount , List<Draf
181186
182187 this .address = address ;
183188 this .connections = connectionscontainer ;
184-
189+ tcpNoDelay = false ;
185190 iqueue = new LinkedList <WebSocketImpl >();
186191
187192 decoders = new ArrayList <WebSocketWorker >( decodercount );
@@ -193,6 +198,25 @@ public WebSocketServer( InetSocketAddress address , int decodercount , List<Draf
193198 }
194199 }
195200
201+ /**
202+ * Tests if TCP_NODELAY is enabled.
203+ * @return a boolean indicating whether or not TCP_NODELAY is enabled for new connections.
204+ */
205+ public boolean isTcpNoDelay () {
206+ return tcpNoDelay ;
207+ }
208+
209+ /**
210+ * Setter for tcpNoDelay
211+ *
212+ * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) for new connections
213+ * @param tcpNoDelay true to enable TCP_NODELAY, false to disable.
214+ */
215+ public void setTcpNoDelay ( boolean tcpNoDelay ) {
216+ this .tcpNoDelay = tcpNoDelay ;
217+ }
218+
219+
196220 /**
197221 * Starts the server selectorthread that binds to the currently set port number and
198222 * listeners for WebSocket connection requests. Creates a fixed thread pool with the size {@link WebSocketServer#DECODERS}<br>
@@ -335,7 +359,9 @@ public void run() {
335359 continue ;
336360 }
337361 channel .configureBlocking ( false );
338- WebSocketImpl w = wsf .createWebSocket ( this , drafts , channel .socket () );
362+ Socket socket = channel .socket ();
363+ socket .setTcpNoDelay ( tcpNoDelay );
364+ WebSocketImpl w = wsf .createWebSocket ( this , drafts , socket );
339365 w .key = channel .register ( selector , SelectionKey .OP_READ , w );
340366 try {
341367 w .channel = wsf .wrapChannel ( channel , w .key );
0 commit comments