title: How to open a html file from websocket server?
body: <p>I am using a websocket server to parse some information from a program writing with c++ to a html page.
  I am using the websocket server sample from POCO, 
  my problem is that the html page is generated from the web socket while i want to have the web page dependent from the websocket and that the web client can call the web socket server to give him data whenever it lunches an event like a click of a button.</p>
  
  <p>I tried to call the websocket server from the html page but i think the problem is in the server, how can a server know that a certain page is calling him?</p>
  
  <p>I used this script in my html page to call the websocket whenever i click a button. </p>
  
  <pre><code>function myFunction()
  {
  
       var soc_di="ws://127.0.0.1:9980/ws"
  
    try {
      soc_di.onopen = function() {
        //document.getElementById("wsdi_statustd").style.backgroundColor = "#40ff40";
        document.getElementById("demo").textContent = " websocket connection opened ";
      } 
  
      soc_di.onmessage =function got_packet(msg) {
        //document.getElementById("number").textContent = msg.data + "\n";
        document.getElementById("des").textContent = msg.data + "\n";
      } 
  
      soc_di.onclose = function(){
        //document.getElementById("wsdi_statustd").style.backgroundColor = "#ff4040";
        document.getElementById("demo").textContent = " websocket connection CLOSED ";
      }
    } catch(exception) {
      alert('&lt;p&gt;Error' + exception);  
    }
  
  }
  </code></pre>
  
  <p>and here is the code when the websocket server generate the html page</p>
  
  <pre><code>class PageRequestHandler: public HTTPRequestHandler
      /// Return a HTML document with some JavaScript creating
      /// a WebSocket connection.
  {
  public:
      void handleRequest(HTTPServerRequest&amp; request, HTTPServerResponse&amp; response)
      {
          response.setChunkedTransferEncoding(true);
          response.setContentType("text/html");
          std::ostream&amp; ostr = response.send();
          ostr &lt;&lt; "&lt;html&gt;";
          ostr &lt;&lt; "&lt;head&gt;";
          ostr &lt;&lt; "&lt;title&gt;WebSocketServer&lt;/title&gt;";
          ostr &lt;&lt; "&lt;script type=\"text/javascript\"&gt;";
          ostr &lt;&lt; "function WebSocketTest()";
          ostr &lt;&lt; "{";
          ostr &lt;&lt; "  if (\"WebSocket\" in window)";
          ostr &lt;&lt; "  {";
          ostr &lt;&lt; "    var ws = new WebSocket(\"ws://" &lt;&lt; request.serverAddress().toString() &lt;&lt; "/ws\");";
          ostr &lt;&lt; "    ws.onopen = function()";
          ostr &lt;&lt; "      {";
          ostr &lt;&lt; "        ws.send(\"Hello, world!\");";
          ostr &lt;&lt; "      };";
          ostr &lt;&lt; "    ws.onmessage = function(evt)";
          ostr &lt;&lt; "      { ";
          ostr &lt;&lt; "        var msg = evt.data;";
          ostr &lt;&lt; "        alert(\"Message received: \" + msg);";
          ostr &lt;&lt; "        ws.close();";
          ostr &lt;&lt; "      };";
          ostr &lt;&lt; "    ws.onclose = function()";
          ostr &lt;&lt; "      { ";
          ostr &lt;&lt; "        alert(\"WebSocket closed.\");";
          ostr &lt;&lt; "      };";
          ostr &lt;&lt; "  }";
          ostr &lt;&lt; "  else";
          ostr &lt;&lt; "  {";
          ostr &lt;&lt; "     alert(\"This browser does not support WebSockets.\");";
          ostr &lt;&lt; "  }";
          ostr &lt;&lt; "}";
          ostr &lt;&lt; "&lt;/script&gt;";
          ostr &lt;&lt; "&lt;/head&gt;";
          ostr &lt;&lt; "&lt;body&gt;";
          ostr &lt;&lt; "  &lt;h1&gt;WebSocket Server&lt;/h1&gt;";
          ostr &lt;&lt; "  &lt;p&gt;&lt;a href=\"javascript:WebSocketTest()\"&gt;Run WebSocket Script&lt;/a&gt;&lt;/p&gt;";
          ostr &lt;&lt; "&lt;/body&gt;";
          ostr &lt;&lt; "&lt;/html&gt;";
      }
  };
  </code></pre>