Announcement

Collapse
No announcement yet.

Html5 - bidirectional communication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Hello, JorgeCosta87

    Follow this step,To Html5 - bidirectional communication

    First, what you do is create a Web Socket object with a URL to where you want to establish a connection to:

    HTML Code:
    var ws = new WebSocket("ws://robertnyman.com/wsmagic");
    You have a couple of useful methods:
    view sourceprint?
    HTML Code:
    // Send data
    ws.send("Some data");
    
    // Close the connection
    ws.close();
    And to complement that, there are a number of events:
    HTML Code:
    // When connection is opened?
    ws.onopen = function () {
    console.log("Connection opened!");
    };??
    
    // When you receive a message
    ws.onmessage = function (evt) {
    console.log(evt.data);
    };
    
    // When the connections is closed
    ws.onclose = function () {
    console.log("Connection closed");
    };
    
    // When an error occurred
    ws.onerror = function () {
    console.log("An error occurred");
    };
    I hope this information will be usefull for you.
    Thank You.

    Leave a comment:


  • started a topic Html5 - bidirectional communication

    Html5 - bidirectional communication

    How to exchange messages from HTML page to unreal element and vice-versa?

    Best regards, Jorge Costa
Working...
X