diff options
Diffstat (limited to 'cask/util/src-jvm')
-rw-r--r-- | cask/util/src-jvm/cask/util/WebsocketClientImpl.scala | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/cask/util/src-jvm/cask/util/WebsocketClientImpl.scala b/cask/util/src-jvm/cask/util/WebsocketClientImpl.scala index 5570356..3344ce4 100644 --- a/cask/util/src-jvm/cask/util/WebsocketClientImpl.scala +++ b/cask/util/src-jvm/cask/util/WebsocketClientImpl.scala @@ -4,8 +4,9 @@ import org.java_websocket.handshake.ServerHandshake abstract class WebsocketClientImpl(url: String) extends WebsocketBase{ var websocket: Client = null - + var closed = false def connect(): Unit = { + assert(closed == false) websocket = new Client() websocket.connect() } @@ -25,15 +26,20 @@ abstract class WebsocketClientImpl(url: String) extends WebsocketBase{ } def onClose(code: Int, reason: String): Unit def onError(ex: Exception): Unit - def close(): Unit = websocket.close() + def close(): Unit = { + if (!closed) websocket.close() + } def isClosed() = websocket.isClosed() class Client() extends WebSocketClient(new java.net.URI(url)){ def onOpen(handshakedata: ServerHandshake) = { WebsocketClientImpl.this.onOpen() } def onMessage(message: String) = WebsocketClientImpl.this.onMessage(message) - def onClose(code: Int, reason: String, remote: Boolean) = WebsocketClientImpl.this.onClose(code, reason) + def onClose(code: Int, reason: String, remote: Boolean) = { + closed = true + WebsocketClientImpl.this.onClose(code, reason) + } def onError(ex: Exception) = WebsocketClientImpl.this.onError(ex) } -}
\ No newline at end of file +} |