diff --git a/tutorials/http/ws.C b/tutorials/http/ws.C index c20fb46a8456aa7228732a5256454c93b5be166d..868f7fec41a38bc9dd793db56c4f025a01e8bd02 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 906ef0dcb983d570f9d01d89e8b6d0cd1d286e89..1c9d3907e3fae82321220f2330a8b8dad6b75613 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>