Top Description Fields Constructors Methods
org.java_websocket

public abstract Class AbstractWebSocket

extends WebSocketAdapter
Class Inheritance
Known Direct Subclasses
org.java_websocket.client.WebSocketClient, org.java_websocket.server.WebSocketServer
Imports
java.util.ArrayList, .Collection, java.util.concurrent.Executors, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, org.java_websocket.framing.CloseFrame, org.java_websocket.util.NamedThreadFactory, org.slf4j.Logger, .LoggerFactory

Base class for additional implementations for the server as well as the client

Field Summary

Modifier and TypeField and Description
private ScheduledFuture<?>
connectionLostCheckerFuture

Attribute for a task that checks for lost connections

private ScheduledExecutorService
connectionLostCheckerService

Attribute for a service that triggers lost connection checking

private long
connectionLostTimeout

Attribute for the lost connection check interval in nanoseconds

private boolean
daemon

Attribute to start internal threads as daemon

protected static int
DEFAULT_READ_BUFFER_SIZE

Used for internal buffer allocations when the socket buffer size is not specified.

private final Logger
log

Logger instance

private int
receiveBufferSize

TCP receive buffer size that will be used for sockets (zero means use system default)

private boolean
reuseAddr

Attribute which allows you to enable/disable the SO_REUSEADDR socket option.

private final Object
syncConnectionLost

Attribute to sync on

private boolean
tcpNoDelay

Attribute which allows you to deactivate the Nagle's algorithm

private boolean
websocketRunning

Attribute to keep track if the WebSocket Server/Client is running/connected

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
cancelConnectionLostTimer()

Cancel any running timer for the connection lost detection

private void
executeConnectionLostDetection(WebSocket
the websocket instance
webSocket
,
long
the lowest/oldest allowable last pong time (in nanoTime) before we consider the connection to be lost
minimumPongTime
)

Send a ping to the endpoint or close the connection since the other endpoint did not respond with a ping

public int

Returns:

the interval in seconds
getConnectionLostTimeout
()

Get the interval checking for lost connections Default is 60 seconds

protected abstract Collection<WebSocket>

Returns:

the currently available connections
getConnections
()

Getter to get all the currently available connections

public int
getReceiveBufferSize()

Returns the TCP receive buffer size that will be used for sockets (or zero, if not explicitly set).

public boolean

Returns:

whether internal threads are spawned in daemon mode
isDaemon
()

Getter for daemon

public boolean

Returns:

a boolean indicating whether or not SO_REUSEADDR is enabled.
isReuseAddr
()

Tests Tests if SO_REUSEADDR is enabled.

public boolean

Returns:

a boolean indicating whether or not TCP_NODELAY is enabled for new connections.
isTcpNoDelay
()

Tests if TCP_NODELAY is enabled.

private void
restartConnectionLostTimer()

This methods allows the reset of the connection lost timer in case of a changed parameter

public void
setConnectionLostTimeout(int
the interval in seconds
connectionLostTimeout
)

Setter for the interval checking for lost connections A value lower or equal 0 results in the check to be deactivated

public void
setDaemon(boolean daemon)

Setter for daemon

Controls whether or not internal threads are spawned in daemon mode

public void
setReceiveBufferSize(int receiveBufferSize)

Sets the TCP receive buffer size that will be used for sockets.

public void
setReuseAddr(boolean
whether to enable or disable SO_REUSEADDR
reuseAddr
)

Setter for soReuseAddr

Enable/disable SO_REUSEADDR for the socket

public void
setTcpNoDelay(boolean
true to enable TCP_NODELAY, false to disable.
tcpNoDelay
)

Setter for tcpNoDelay

Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) for new connections

protected void
startConnectionLostTimer()

Start the connection lost timer

protected void
stopConnectionLostTimer()

Stop the connection lost timer

Inherited from org.java_websocket.WebSocketAdapter:
onPreparePingonWebsocketHandshakeReceivedAsClientonWebsocketHandshakeReceivedAsServeronWebsocketHandshakeSentAsClientonWebsocketPingonWebsocketPong

Field Detail

connectionLostCheckerFutureback to summary
private ScheduledFuture<?> connectionLostCheckerFuture

Attribute for a task that checks for lost connections

Since
1.4.1
connectionLostCheckerServiceback to summary
private ScheduledExecutorService connectionLostCheckerService

Attribute for a service that triggers lost connection checking

Since
1.4.1
connectionLostTimeoutback to summary
private long connectionLostTimeout

Attribute for the lost connection check interval in nanoseconds

Since
1.3.4
daemonback to summary
private boolean daemon

Attribute to start internal threads as daemon

Since
1.5.6
DEFAULT_READ_BUFFER_SIZEback to summary
protected static int DEFAULT_READ_BUFFER_SIZE

Used for internal buffer allocations when the socket buffer size is not specified.

logback to summary
private final Logger log

Logger instance

Since
1.4.0
receiveBufferSizeback to summary
private int receiveBufferSize

TCP receive buffer size that will be used for sockets (zero means use system default)

Since
1.5.7
reuseAddrback to summary
private boolean reuseAddr

Attribute which allows you to enable/disable the SO_REUSEADDR socket option.

Since
1.3.5
syncConnectionLostback to summary
private final Object syncConnectionLost

Attribute to sync on

tcpNoDelayback to summary
private boolean tcpNoDelay

Attribute which allows you to deactivate the Nagle's algorithm

Since
1.3.3
websocketRunningback to summary
private boolean websocketRunning

Attribute to keep track if the WebSocket Server/Client is running/connected

Since
1.3.9

Constructor Detail

AbstractWebSocketback to summary
public AbstractWebSocket()

Method Detail

cancelConnectionLostTimerback to summary
private void cancelConnectionLostTimer()

Cancel any running timer for the connection lost detection

Since
1.3.4
executeConnectionLostDetectionback to summary
private void executeConnectionLostDetection(WebSocket webSocket, long minimumPongTime)

Send a ping to the endpoint or close the connection since the other endpoint did not respond with a ping

Parameters
webSocket:WebSocket

the websocket instance

minimumPongTime:long

the lowest/oldest allowable last pong time (in nanoTime) before we consider the connection to be lost

getConnectionLostTimeoutback to summary
public int getConnectionLostTimeout()

Get the interval checking for lost connections Default is 60 seconds

Returns:int

the interval in seconds

Since
1.3.4
getConnectionsback to summary
protected abstract Collection<WebSocket> getConnections()

Getter to get all the currently available connections

Returns:Collection<WebSocket>

the currently available connections

Since
1.3.4
getReceiveBufferSizeback to summary
public int getReceiveBufferSize()

Returns the TCP receive buffer size that will be used for sockets (or zero, if not explicitly set).

Since
1.5.7
See Also
java.net.Socket#setReceiveBufferSize(int)
isDaemonback to summary
public boolean isDaemon()

Getter for daemon

Returns:boolean

whether internal threads are spawned in daemon mode

Since
1.5.6
isReuseAddrback to summary
public boolean isReuseAddr()

Tests Tests if SO_REUSEADDR is enabled.

Returns:boolean

a boolean indicating whether or not SO_REUSEADDR is enabled.

Since
1.3.5
isTcpNoDelayback to summary
public boolean isTcpNoDelay()

Tests if TCP_NODELAY is enabled.

Returns:boolean

a boolean indicating whether or not TCP_NODELAY is enabled for new connections.

Since
1.3.3
restartConnectionLostTimerback to summary
private void restartConnectionLostTimer()

This methods allows the reset of the connection lost timer in case of a changed parameter

Since
1.3.4
setConnectionLostTimeoutback to summary
public void setConnectionLostTimeout(int connectionLostTimeout)

Setter for the interval checking for lost connections A value lower or equal 0 results in the check to be deactivated

Parameters
connectionLostTimeout:int

the interval in seconds

Since
1.3.4
setDaemonback to summary
public void setDaemon(boolean daemon)

Setter for daemon

Controls whether or not internal threads are spawned in daemon mode

Since
1.5.6
setReceiveBufferSizeback to summary
public void setReceiveBufferSize(int receiveBufferSize)

Sets the TCP receive buffer size that will be used for sockets. If this is not explicitly set (or set to zero), the system default is used.

Since
1.5.7
See Also
java.net.Socket#setReceiveBufferSize(int)
setReuseAddrback to summary
public void setReuseAddr(boolean reuseAddr)

Setter for soReuseAddr

Enable/disable SO_REUSEADDR for the socket

Parameters
reuseAddr:boolean

whether to enable or disable SO_REUSEADDR

Since
1.3.5
setTcpNoDelayback to summary
public void setTcpNoDelay(boolean tcpNoDelay)

Setter for tcpNoDelay

Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) for new connections

Parameters
tcpNoDelay:boolean

true to enable TCP_NODELAY, false to disable.

Since
1.3.3
startConnectionLostTimerback to summary
protected void startConnectionLostTimer()

Start the connection lost timer

Since
1.3.4
stopConnectionLostTimerback to summary
protected void stopConnectionLostTimer()

Stop the connection lost timer

Since
1.3.4