generated from iAndyHD3/xmake-gd-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Examples
iAndyHD3 edited this page May 19, 2024
·
2 revisions
This mod host a websocket server on the address localhost:1313 and 127.0.0.1:1313.
You can interact with geometry dash using this address with a websocket client.
You need to open a connection with this server and send a JSON request.
In java, you can create a websocket using the following API: (maven)
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.6</version>
</dependency>You can then create a websocket with a class that extend WebSocketClient.
Your class should look something like this:
import org.java_websocket.client.WebSocketClient;
public class WSClient extends WebSocketClient {
List<String> msg;
public WSClient(URI serverUri, ArrayList<String> message) {
super(serverUri);
msg = message;
}
@Override
public void onOpen(ServerHandshake serverHandshake) {
msg.forEach(message -> {
send(message);
});
close();
}
@Override
public void onMessage(String s) {
}
@Override
public void onClose(int i, String s, boolean b) {
}
@Override
public void onError(Exception e) {
}
}then you can call
new WSClient(URI.create("ws://127.0.0.1:1313"), new ArrayList<String>()).run();This will open a connection to the websocket server, then send a list of string as request.