From 2b26a73b70f9660d7a57bd5e30600fd75a2f8da7 Mon Sep 17 00:00:00 2001
From: Sergey Linev <S.Linev@gsi.de>
Date: Wed, 22 Aug 2018 12:55:58 +0200
Subject: [PATCH] http: update websocket tutorial

---
 tutorials/http/ws.C   |  7 ++++---
 tutorials/http/ws.htm | 17 +++++++++--------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/tutorials/http/ws.C b/tutorials/http/ws.C
index c20fb46a845..868f7fec41a 100644
--- a/tutorials/http/ws.C
+++ b/tutorials/http/ws.C
@@ -11,8 +11,9 @@
 class TUserHandler : public THttpWSHandler {
    public:
       UInt_t fWSId;
+      Int_t fServCnt;
 
-      TUserHandler(const char *name = 0, const char *title = 0) : THttpWSHandler(name, title), fWSId(0) {}
+      TUserHandler(const char *name = 0, const char *title = 0) : THttpWSHandler(name, title), fWSId(0), fServCnt(0) {}
 
       // load custom HTML page when open correpondent address
       TString GetDefaultPageContent() { return "file:ws.htm"; }
@@ -42,7 +43,7 @@ class TUserHandler : public THttpWSHandler {
            TString str = arg->GetPostDataAsString();
            printf("Client msg: %s\n", str.Data());
            TDatime now;
-           SendCharStarWS(arg->GetWSId(), Form("Server replies %s", now.AsString()));
+           SendCharStarWS(arg->GetWSId(), Form("Server replies:%s server counter:%d", now.AsString(), fServCnt++));
            return kTRUE;
         }
 
@@ -53,7 +54,7 @@ class TUserHandler : public THttpWSHandler {
       virtual Bool_t HandleTimer(TTimer *)
       {
          TDatime now;
-         if (fWSId) SendCharStarWS(fWSId, Form("Server sends data %s", now.AsString()));
+         if (fWSId) SendCharStarWS(fWSId, Form("Server sends data:%s server counter:%d", now.AsString(), fServCnt++));
          return kTRUE;
       }
 
diff --git a/tutorials/http/ws.htm b/tutorials/http/ws.htm
index 906ef0dcb98..1c9d3907e3f 100644
--- a/tutorials/http/ws.htm
+++ b/tutorials/http/ws.htm
@@ -11,20 +11,21 @@
       <h3>Log protocol:</h3>
       <div id="LogDiv"></div>
    </body>
-   
+
    <script type='text/javascript'>
-   
+
       var path = window.location.href;
       path = path.replace("http://", "ws://") + "root.websocket";
+      var cnt  = 0;
 
       function show(str) {
          document.getElementById('LogDiv').insertAdjacentHTML( 'beforeend', '<text>' + str + '</text><br/>');
          console.log(str);
       }
-   
+
       console.log('starting socket ' + path);
       var socket = new WebSocket(path);
-      
+
       socket.onopen = function() {
          show('websocket initialized');
          this._ready = true;
@@ -34,7 +35,7 @@
       socket.onmessage = function(e) {
          var msg = e.data;
          if (typeof msg != 'string') return console.log("unsupported message kind: " + (typeof msg));
-         
+
          show('get: ' + msg);
       }
 
@@ -48,11 +49,11 @@
          this._ready = false;
          show('websocket error' + err);
       }
-      
+
       // sends data every 5 seconds
       setInterval(function() {
-         if (socket._ready) socket.send("Client time " + new Date().toTimeString());
-      }, 5000);
+         if (socket._ready) socket.send("Client time " + new Date().toTimeString() + " client counter:" + (cnt++));
+      }, 1000);
 
    </script>
 
-- 
GitLab