From bb058bb98965ff09e01a619ba5ee0929c8dea444 Mon Sep 17 00:00:00 2001 From: data Date: Thu, 10 Apr 2025 21:49:10 +0200 Subject: [PATCH] =?UTF-8?q?client=20Ordner=20als=20normale=20Dateien=20hin?= =?UTF-8?q?zugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client | 1 - client/client.js | 34 ++++++++++++++++++++++++++++++++++ client/index.html | 10 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) delete mode 160000 client create mode 100644 client/client.js create mode 100644 client/index.html diff --git a/client b/client deleted file mode 160000 index 9cbce74..0000000 --- a/client +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9cbce7415d2429d2132afb3b1d985c09f6ddd7f2 diff --git a/client/client.js b/client/client.js new file mode 100644 index 0000000..e285ffa --- /dev/null +++ b/client/client.js @@ -0,0 +1,34 @@ +/** + * @returns {Promise<{server_ip: string, server_port: number}>} + */ +async function getServerConfig() { + const response = await fetch('/api/ip'); + return await response.json(); +} + +getServerConfig() + .then(data => { + const websocketIp = data.server_ip; + const websocketPort = data.server_port; + const ws = new WebSocket(`ws://${websocketIp}:${websocketPort}`); + + ws.onopen = function() { + console.log("WebSocket ist geƶffnet"); + ws.send(JSON.stringify({"data_message": "Server Adresse: " + websocketIp + ":" + websocketPort})); + }; + + ws.onmessage = function(messageEvent) { + console.log(messageEvent.data); + }; + + ws.onclose = function() { + console.log("WebSocket wurde geschlossen"); + }; + + ws.onerror = function(errorEvent) { + console.error("WebSocket-Fehler: ", errorEvent); + }; + }) + .catch(error => { + console.error('Error fetching settings:', error); + }); diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..6674623 --- /dev/null +++ b/client/index.html @@ -0,0 +1,10 @@ + + + + + Websocket Client + + + + + \ No newline at end of file