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