diff options
author | Florian Rinke <develop@torui.de> | 2021-09-22 22:50:20 +0200 |
---|---|---|
committer | Florian Rinke <develop@torui.de> | 2021-09-22 22:50:20 +0200 |
commit | e5e0c9a3a4fd9b2c10464e0f129bcb60b2db0f19 (patch) | |
tree | 139bc2d1228387720672749a7adbaacc81558f08 /src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java | |
parent | de2ef874edada810845cf902402337cd8809dd12 (diff) | |
download | COFL-e5e0c9a3a4fd9b2c10464e0f129bcb60b2db0f19.tar.gz COFL-e5e0c9a3a4fd9b2c10464e0f129bcb60b2db0f19.tar.bz2 COFL-e5e0c9a3a4fd9b2c10464e0f129bcb60b2db0f19.zip |
.
Diffstat (limited to 'src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java b/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java new file mode 100644 index 0000000..ef2ee8b --- /dev/null +++ b/src/main/java/de/torui/coflsky/websocket/WSClientWrapper.java @@ -0,0 +1,53 @@ +package de.torui.coflsky.websocket; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.UUID; + +import de.torui.coflsky.CoflSky; +import de.torui.coflsky.core.Command; + + +public class WSClientWrapper { + public WSClient socket; + public Thread thread; + public boolean isRunning; + public String uri = ""; + + public WSClientWrapper(String uri) { + this.uri = uri; + } + + public synchronized void start() { + if(!isRunning) { + String uuid = CoflSky.PlayerUUID; + try { + socket = new WSClient(new URI(uri + uuid)); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + thread = new Thread(socket); + thread.start(); + isRunning=true; + } + } + + public synchronized void stop() { + if(isRunning) { + try { + socket.closeBlocking(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + isRunning = false; + socket = null; + socket = null; + } + } + + public synchronized void SendMessage(Command cmd){ + this.socket.SendCommand(cmd); + } +} |