34 lines
1.0 KiB
HTML
34 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Baeldung: Spring 5 Reactive Client WebSocket (Browser)</title>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="events"></div>
|
|
<script>
|
|
var clientWebSocket = new WebSocket("ws://localhost:8080/event-emitter");
|
|
clientWebSocket.onopen = function() {
|
|
console.log("clientWebSocket.onopen", clientWebSocket);
|
|
console.log("clientWebSocket.readyState", "websocketstatus");
|
|
clientWebSocket.send("event-me-from-browser");
|
|
}
|
|
clientWebSocket.onclose = function(error) {
|
|
console.log("clientWebSocket.onclose", clientWebSocket, error);
|
|
events("Closing connection");
|
|
}
|
|
clientWebSocket.onerror = function(error) {
|
|
console.log("clientWebSocket.onerror", clientWebSocket, error);
|
|
events("An error occured");
|
|
}
|
|
clientWebSocket.onmessage = function(error) {
|
|
console.log("clientWebSocket.onmessage", clientWebSocket, error);
|
|
events(error.data);
|
|
}
|
|
function events(responseEvent) {
|
|
document.querySelector(".events").innerHTML += responseEvent + "<br>";
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |