Package com.basiscomponents.comm
Class WsServer
- java.lang.Object
-
- org.java_websocket.WebSocketAdapter
-
- org.java_websocket.AbstractWebSocket
-
- org.java_websocket.server.WebSocketServer
-
- com.basiscomponents.comm.WsServer
-
- All Implemented Interfaces:
Runnable
,WebSocketListener
public class WsServer extends WebSocketServer
A simple WebSocketServer implementation. Keeps track of a "chatroom".
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.java_websocket.server.WebSocketServer
WebSocketServer.WebSocketWorker
-
-
Field Summary
Fields Modifier and Type Field Description static Boolean
DEBUG
-
Fields inherited from class org.java_websocket.server.WebSocketServer
decoders, DECODERS
-
-
Constructor Summary
Constructors Constructor Description WsServer(int port)
WsServer(InetSocketAddress address)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Object
getInstance(com.basis.bbj.proxies.BBjAPI api, int port)
void
onClose(WebSocket conn, int code, String reason, boolean remote)
Called after the websocket connection has been closed.void
onError(WebSocket conn, Exception ex)
Called when errors occurs.void
onMessage(WebSocket conn, String message)
Callback for string messages received from the remote hostvoid
onMessage(WebSocket conn, ByteBuffer message)
Callback for binary messages received from the remote hostvoid
onOpen(WebSocket conn, ClientHandshake handshake)
Called after an opening handshake has been performed and the given websocket is ready to be written on.void
onStart()
Called when the server started up successfully.void
send(String tag, String message)
void
setEventDispatcher(CrossEventDispatcher ed)
-
Methods inherited from class org.java_websocket.server.WebSocketServer
addConnection, allocateBuffers, broadcast, broadcast, broadcast, broadcast, broadcast, broadcast, connections, createBuffer, getAddress, getConnections, getDraft, getLocalSocketAddress, getPort, getRemoteSocketAddress, getWebSocketFactory, onCloseInitiated, onClosing, onConnect, onFragment, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketHandshakeReceivedAsServer, onWebsocketMessage, onWebsocketMessage, onWebsocketMessageFragment, onWebsocketOpen, onWriteDemand, queue, releaseBuffers, removeConnection, run, setWebSocketFactory, start, stop, stop
-
Methods inherited from class org.java_websocket.AbstractWebSocket
getConnectionLostTimeout, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimer
-
Methods inherited from class org.java_websocket.WebSocketAdapter
onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
-
-
-
-
Field Detail
-
DEBUG
public static Boolean DEBUG
-
-
Constructor Detail
-
WsServer
public WsServer(int port) throws UnknownHostException
- Throws:
UnknownHostException
-
WsServer
public WsServer(InetSocketAddress address)
-
-
Method Detail
-
onOpen
public void onOpen(WebSocket conn, ClientHandshake handshake)
Description copied from class:WebSocketServer
Called after an opening handshake has been performed and the given websocket is ready to be written on.- Specified by:
onOpen
in classWebSocketServer
- Parameters:
conn
- The WebSocket instance this event is occuring on.handshake
- The handshake of the websocket instance
-
setEventDispatcher
public void setEventDispatcher(CrossEventDispatcher ed)
-
onClose
public void onClose(WebSocket conn, int code, String reason, boolean remote)
Description copied from class:WebSocketServer
Called after the websocket connection has been closed.- Specified by:
onClose
in classWebSocketServer
- Parameters:
conn
- The WebSocket instance this event is occuring on.code
- The codes can be looked up here:CloseFrame
reason
- Additional information stringremote
- Returns whether or not the closing of the connection was initiated by the remote host.
-
onMessage
public void onMessage(WebSocket conn, String message)
Description copied from class:WebSocketServer
Callback for string messages received from the remote host- Specified by:
onMessage
in classWebSocketServer
- Parameters:
conn
- The WebSocket instance this event is occuring on.message
- The UTF-8 decoded message that was received.- See Also:
WebSocketServer.onMessage(WebSocket, ByteBuffer)
-
onMessage
public void onMessage(WebSocket conn, ByteBuffer message)
Description copied from class:WebSocketServer
Callback for binary messages received from the remote host- Overrides:
onMessage
in classWebSocketServer
- Parameters:
conn
- The WebSocket instance this event is occurring on.message
- The binary message that was received.- See Also:
WebSocketServer.onMessage(WebSocket, ByteBuffer)
-
onError
public void onError(WebSocket conn, Exception ex)
Description copied from class:WebSocketServer
Called when errors occurs. If an error causes the websocket connection to failWebSocketServer.onClose(WebSocket, int, String, boolean)
will be called additionally.
This method will be called primarily because of IO or protocol errors.
If the given exception is an RuntimeException that probably means that you encountered a bug.- Specified by:
onError
in classWebSocketServer
- Parameters:
conn
- Can be null if there error does not belong to one specific websocket. For example if the servers port could not be bound.ex
- The exception causing this error
-
onStart
public void onStart()
Description copied from class:WebSocketServer
Called when the server started up successfully. If any error occured, onError is called instead.- Specified by:
onStart
in classWebSocketServer
-
getInstance
public static Object getInstance(com.basis.bbj.proxies.BBjAPI api, int port) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyManagementException
-
-