Commit 868b6113bfca026a0d40919db79dd9ed40670f17
1 parent
9d81e68a
feature: Testdatei "websockets.html" hinzugefügt
Showing
1 changed file
with
43 additions
and
0 deletions
src/main/webapp/websockets.html
0 → 100644
| 1 | +<!DOCTYPE html> | |
| 2 | +<html lang="en"> | |
| 3 | +<head> | |
| 4 | + <meta charset="UTF-8"> | |
| 5 | + <title>Test WebSockets</title> | |
| 6 | +</head> | |
| 7 | +<body> | |
| 8 | + <script> | |
| 9 | + var url = "ws://localhost:8080/swxercise/ws/api/v1/test"; | |
| 10 | + var webSocket = new WebSocket(url); | |
| 11 | + | |
| 12 | + // Callback-Methoden für die WebSocket-Kommunikation | |
| 13 | + webSocket.onopen = function(e) { onWebSocketOpen(e) }; | |
| 14 | + webSocket.onclose = function(e) { onWebSocketClose(e) }; | |
| 15 | + webSocket.onmessage = function(e) { onWebSocketMessage(e) }; | |
| 16 | + webSocket.onerror = function(e) { onWebSocketError(e) }; | |
| 17 | + | |
| 18 | + function onWebSocketOpen(e) { | |
| 19 | + console.log("WebSocket has been opened."); | |
| 20 | + } | |
| 21 | + | |
| 22 | + function onWebSocketClose(e) { | |
| 23 | + console.log("WebSocket has been closed."); | |
| 24 | + } | |
| 25 | + | |
| 26 | + function onWebSocketMessage(e) { | |
| 27 | + console.log("WebSocket Message '" + e.data + "' has been received."); | |
| 28 | + } | |
| 29 | + | |
| 30 | + function onWebSocketError(e) { | |
| 31 | + alert("WebSocket Error " + e + " has been thrown!"); | |
| 32 | + } | |
| 33 | + | |
| 34 | + function sendWebSocketMessage() { | |
| 35 | + if (webSocket.send('Hello World!')) | |
| 36 | + console.log("WebSocket Message sent."); | |
| 37 | + else | |
| 38 | + alert("WebSocket Message not sent!"); | |
| 39 | + } | |
| 40 | + </script> | |
| 41 | + <button onclick="sendWebSocketMessage()">Klick mich.</button> | |
| 42 | +</body> | |
| 43 | +</html> | |
| 0 | 44 | \ No newline at end of file | ... | ... |