Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > d7a0ff090fe8b5198bd2a4b1518b0fde > files > 51

qtwebsockets5-doc-5.12.6-1.1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>chatclient.html Example File | Qt WebSockets 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtwebsockets-index.html">Qt WebSockets</a></td><td ><a href="qtwebsockets-simplechat-example.html">Simple Chat Example</a></td><td >chatclient.html Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwebsockets-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">chatclient.html Example File</h1>
<span class="subtitle">simplechat/chatclient.html</span>
<!-- $$$simplechat/chatclient.html-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;WebSocket Chat Client&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;WebSocket Chat Client&lt;/h1&gt;
          &lt;p&gt;
              Host: &lt;input id=&quot;webSocketHost&quot; type=&quot;text&quot; value=&quot;localhost:1234&quot;/&gt;
          &lt;/p&gt;
          &lt;p&gt;
              &lt;button onClick=&quot;initWebSocket();&quot;&gt;Connect&lt;/button&gt;
              &lt;button id=&quot;disconnectButton&quot; onClick=&quot;stopWebSocket();&quot; disabled&gt;Disconnect&lt;/button&gt;
              &lt;button onClick=&quot;checkSocket();&quot;&gt;State&lt;/button&gt;
          &lt;/p&gt;
          &lt;p&gt;
              &lt;textarea id=&quot;debugTextArea&quot; style=&quot;width:400px;height:200px;&quot; readonly&gt;&lt;/textarea&gt;
          &lt;/p&gt;
          &lt;p&gt;
              &lt;input type=&quot;text&quot; id=&quot;inputNick&quot; value=&quot;nickname&quot; /&gt;
              &lt;input type=&quot;text&quot; id=&quot;inputText&quot; onkeydown=&quot;if(event.keyCode==13)sendMessage();&quot;/&gt;
              &lt;button id=&quot;sendButton&quot; onClick=&quot;sendMessage();&quot; disabled&gt;Send&lt;/button&gt;
          &lt;/p&gt;

          &lt;script type=&quot;text/javascript&quot;&gt;
              var debugTextArea = document.getElementById(&quot;debugTextArea&quot;);
              function debug(message) {
                  debugTextArea.value += message + &quot;\n&quot;;
                  debugTextArea.scrollTop = debugTextArea.scrollHeight;
              }

              function sendMessage() {
                  var nickname = document.getElementById(&quot;inputNick&quot;).value;
                  var msg = document.getElementById(&quot;inputText&quot;).value;
                  var strToSend = nickname + &quot;: &quot; + msg;
                  if ( websocket != null )
                  {
                      document.getElementById(&quot;inputText&quot;).value = &quot;&quot;;
                      websocket.send( strToSend );
                      console.log( &quot;string sent :&quot;, '&quot;'+strToSend+'&quot;' );
                      debug(strToSend);
                  }
              }

              var websocket = null;

              function initWebSocket() {
                  try {
                      if (typeof MozWebSocket == 'function')
                          WebSocket = MozWebSocket;
                      if ( websocket &amp;&amp; websocket.readyState == 1 )
                          websocket.close();
                      var wsUri = &quot;ws://&quot; + document.getElementById(&quot;webSocketHost&quot;).value;
                      websocket = new WebSocket( wsUri );
                      websocket.onopen = function (evt) {
                          debug(&quot;CONNECTED&quot;);
                          document.getElementById(&quot;disconnectButton&quot;).disabled = false;
                          document.getElementById(&quot;sendButton&quot;).disabled = false;
                      };
                      websocket.onclose = function (evt) {
                          debug(&quot;DISCONNECTED&quot;);
                          document.getElementById(&quot;disconnectButton&quot;).disabled = true;
                          document.getElementById(&quot;sendButton&quot;).disabled = true;
                      };
                      websocket.onmessage = function (evt) {
                          console.log( &quot;Message received :&quot;, evt.data );
                          debug( evt.data );
                      };
                      websocket.onerror = function (evt) {
                          debug('ERROR: ' + evt.data);
                      };
                  } catch (exception) {
                      debug('ERROR: ' + exception);
                  }
              }

              function stopWebSocket() {
                  if (websocket)
                      websocket.close();
              }

              function checkSocket() {
                  if (websocket != null) {
                      var stateStr;
                      switch (websocket.readyState) {
                          case 0: {
                              stateStr = &quot;CONNECTING&quot;;
                              break;
                          }
                          case 1: {
                              stateStr = &quot;OPEN&quot;;
                              break;
                          }
                          case 2: {
                              stateStr = &quot;CLOSING&quot;;
                              break;
                          }
                          case 3: {
                              stateStr = &quot;CLOSED&quot;;
                              break;
                          }
                          default: {
                              stateStr = &quot;UNKNOW&quot;;
                              break;
                          }
                      }
                      debug(&quot;WebSocket state = &quot; + websocket.readyState + &quot; ( &quot; + stateStr + &quot; )&quot;);
                  } else {
                      debug(&quot;WebSocket is null&quot;);
                  }
              }
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;

</pre>
</div>
<!-- @@@simplechat/chatclient.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>