diff options
author | Florian Rinke <develop@torui.de> | 2021-09-05 12:08:18 +0200 |
---|---|---|
committer | Florian Rinke <develop@torui.de> | 2021-09-05 12:08:18 +0200 |
commit | f88b74485ffdf42ca2b62c72fb746082e7fc012f (patch) | |
tree | 7c536169d9b50a098549daa469f970e672b3dd19 /src/main/java/de/torui/coflsky/websocket/WSClient.java | |
parent | d574e83ac221ce7b74756cfa8417904831ea245e (diff) | |
download | COFL-f88b74485ffdf42ca2b62c72fb746082e7fc012f.tar.gz COFL-f88b74485ffdf42ca2b62c72fb746082e7fc012f.tar.bz2 COFL-f88b74485ffdf42ca2b62c72fb746082e7fc012f.zip |
add to github
Diffstat (limited to 'src/main/java/de/torui/coflsky/websocket/WSClient.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/websocket/WSClient.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClient.java b/src/main/java/de/torui/coflsky/websocket/WSClient.java new file mode 100644 index 0000000..dac8ae5 --- /dev/null +++ b/src/main/java/de/torui/coflsky/websocket/WSClient.java @@ -0,0 +1,68 @@ +package de.torui.coflsky.websocket; +import java.net.URI; +import java.util.LinkedList; +import java.util.Queue; + +import org.java_websocket.client.WebSocketClient; +import org.java_websocket.handshake.ServerHandshake; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import de.torui.coflsky.core.Command; + + +public class WSClient extends WebSocketClient{ + + private static Gson gson; + + public static WSClient Instancce; + + + static { + gson = new GsonBuilder()/*.setFieldNamingStrategy(new FieldNamingStrategy() { + @Override + public String translateName(Field f) { + + String name = f.getName(); + char firstChar = name.charAt(0); + return Character.toLowerCase(firstChar) + name.substring(1); + } + })*/.create(); + } + + public WSClient(URI serverUri) { + super(serverUri); + + } + + @Override + public void onOpen(ServerHandshake handshakedata) { + + } + + @Override + public void onMessage(String message) { + System.out.println(message); + + Command cmd = gson.fromJson(message, Command.class); + + + System.out.println(cmd); + } + + @Override + public void onClose(int code, String reason, boolean remote) { + System.out.printf("code: %n reason:%s remote:%b", code, reason,remote); + } + + @Override + public void onError(Exception ex) { + ex.printStackTrace(); + } + + public void SendCommand(Command command) { + + } + +} |