HTML5 WebSockets

 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

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...