forked from i21017/JavaCompilerCore
Compare commits
2 Commits
28458d405f
...
0129d7540f
Author | SHA1 | Date | |
---|---|---|---|
|
0129d7540f | ||
|
7ea8337aee |
7
pom.xml
7
pom.xml
@@ -49,11 +49,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
@@ -158,4 +153,4 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<url>file:///${project.basedir}/maven-repository/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
</project>
|
||||
|
@@ -14,7 +14,6 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -39,9 +38,13 @@ public class SocketClient extends WebSocketClient {
|
||||
private UnifyResultPacket unifyResultPacket;
|
||||
|
||||
public SocketClient(String url) {
|
||||
super(URI.create(url), Map.of(
|
||||
"packetProtocolVersion", SocketServer.packetProtocolVersion
|
||||
));
|
||||
super(
|
||||
URI.create(url), // target url
|
||||
SocketServer.perMessageDeflateDraft, // enable compression
|
||||
Map.of( // headers
|
||||
"packetProtocolVersion", SocketServer.packetProtocolVersion
|
||||
)
|
||||
);
|
||||
// make sure, the url is in a valid format
|
||||
final String regex = "^wss?://(\\w+(\\.\\w+)?)*:(\\d+)$";
|
||||
final Matcher matcher = Pattern.compile(regex).matcher(url);
|
||||
@@ -51,7 +54,7 @@ public class SocketClient extends WebSocketClient {
|
||||
}
|
||||
|
||||
public SocketClient(String host, int port, boolean secure) {
|
||||
super(URI.create(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port)));
|
||||
this(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +90,7 @@ public class SocketClient extends WebSocketClient {
|
||||
System.err.println("Server connection interrupted: " + exception);
|
||||
this.notifyAll();
|
||||
throw new RuntimeException("Aborted server connection", exception);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException("Exception occurred in server connection: ", exception);
|
||||
}
|
||||
|
||||
@@ -101,15 +103,14 @@ public class SocketClient extends WebSocketClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific client-side implementations to handle incoming packets
|
||||
* Specific client-side implementations to handle incoming packets
|
||||
*/
|
||||
protected void handleReceivedPacket(IPacket packet) {
|
||||
if (packet instanceof IServerToClientPacket serverToClientPacket) {
|
||||
|
||||
try {
|
||||
serverToClientPacket.onHandle(this.getConnection(), this);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
} catch (Exception exception) {
|
||||
this.closeLatch.countDown();
|
||||
this.close();
|
||||
throw exception;
|
||||
|
@@ -9,6 +9,7 @@ import de.dhbwstuttgart.server.packet.MessagePacket;
|
||||
import de.dhbwstuttgart.server.packet.PacketContainer;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -17,7 +18,11 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.drafts.Draft;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.DefaultWebSocketServerFactory;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
|
||||
public class SocketServer extends WebSocketServer {
|
||||
@@ -30,8 +35,14 @@ public class SocketServer extends WebSocketServer {
|
||||
*/
|
||||
public static final String packetProtocolVersion = "1";
|
||||
|
||||
/**
|
||||
* Draft object for enabling the perMessageDeflate extension for more packet compression
|
||||
*/
|
||||
public static final Draft perMessageDeflateDraft = new Draft_6455(new PerMessageDeflateExtension());
|
||||
|
||||
public SocketServer(int port) {
|
||||
super(new InetSocketAddress(port));
|
||||
super(new InetSocketAddress(port), Collections.singletonList(perMessageDeflateDraft));
|
||||
this.setConnectionLostTimeout(30);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,5 +212,4 @@ public class SocketServer extends WebSocketServer {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ public class ErrorPacket implements IClientToServerPacket, IServerToClientPacket
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketClient socketClient) {
|
||||
System.err.println("[socket] " + "ErrorPacket: " + this.error);
|
||||
SocketClient.logger.error("SocketError: " + this.error);
|
||||
if (this.isFatal) {
|
||||
throw new RuntimeException("Received fatal error from server: " + this.error);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ErrorPacket implements IClientToServerPacket, IServerToClientPacket
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketServer socketServer) {
|
||||
socketServer.log("ErrorPacket: " + this.error, webSocket);
|
||||
socketServer.log("SocketError: " + this.error, webSocket);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,8 +24,7 @@ public class MessagePacket implements IClientToServerPacket, IServerToClientPack
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketClient socketClient) {
|
||||
System.err.println("[socket] " + this.message);
|
||||
|
||||
SocketClient.logger.info("SocketMessage: " + this.message);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
|
Reference in New Issue
Block a user