local websocket port requester

This commit is contained in:
sirjonasxx 2020-12-27 21:31:05 +01:00
parent 9a5415a199
commit 5f262cde16
2 changed files with 43 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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> T getEndpointInstance(Class<T> clazz) throws InstantiationException {
return (T)new PortRequester(packetHandlerPort);
}
}