HTML5 WebSockets
WebSockets enable bidirectional communication between a client and a server over a single, long-lived connection. It allows real-time data exchange. Here's an example:
<script>
const socket = new WebSocket("ws://example.com/socket");
socket.onopen = function() {
console.log("WebSocket connection established.");
socket.send("Hello, server!");
};
socket.onmessage = function(event) {
console.log("Received message from server:", event.data);
};
socket.onclose = function() {
console.log("WebSocket connection closed.");
};
</script>
No comments:
Post a Comment