From 5f262cde1678db9a92725778f48f552d5320c48a Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 27 Dec 2020 21:31:05 +0100 Subject: [PATCH] local websocket port requester --- .../connection/proxy/unity/PortRequester.java | 26 +++++++++++++++++++ .../proxy/unity/PortRequesterConfig.java | 17 ++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequester.java create mode 100644 G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequesterConfig.java diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequester.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequester.java new file mode 100644 index 0000000..18aac14 --- /dev/null +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequester.java @@ -0,0 +1,26 @@ +package gearth.protocol.connection.proxy.unity; + +import javafx.beans.InvalidationListener; +import org.eclipse.jetty.websocket.jsr356.annotations.JsrParamIdText; + +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; + +// tells which port the packethandler is running on +// server gets closed afterwards +@ServerEndpoint(value = "/portrequest") +public class PortRequester { + + private final int packetHandlerPort; + + public PortRequester(int port) { + this.packetHandlerPort = port; + } + + @OnOpen + public void onOpen(Session session) throws IOException { + session.getBasicRemote().sendText("port " + packetHandlerPort); + } +} diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequesterConfig.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequesterConfig.java new file mode 100644 index 0000000..90fbd20 --- /dev/null +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/PortRequesterConfig.java @@ -0,0 +1,17 @@ +package gearth.protocol.connection.proxy.unity; + +import javax.websocket.server.ServerEndpointConfig; + +public class PortRequesterConfig extends ServerEndpointConfig.Configurator { + + private final int packetHandlerPort; + + public PortRequesterConfig(int packetHandlerPort) { + this.packetHandlerPort = packetHandlerPort; + } + + public T getEndpointInstance(Class clazz) throws InstantiationException { + return (T)new PortRequester(packetHandlerPort); + } + +}