Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Datasnap REST XE4 and Heavyweight Callbacks


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 19, 2017 5:00 AM Last Post By: Júlio César Men...
Júlio César Men...

Posts: 14
Registered: 3/20/09
Datasnap REST XE4 and Heavyweight Callbacks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 9, 2017 3:04 AM
Hi people,

I am implementing a REST server with default datasnap.

I've been looking at the callback feature using the HTTP long polling technique and am curious about the features of this in Delphi.

Today, I've already been able to send a message by BroadcastMessage method and retrieve it in a basic JavaScript Client. My doubts are:

1. Does the server know which clients are "connected"?
2. Can I retrieve a list of these "connected" clients?
3. Can you tell if a client has "disconnected"?
4. Where do I get relatively good material to study about this on the web?

Thank you very much to all who can help.
Any questions about how to implement the basics of callback in REST, I'm here to give a help too.

Thank you so much!
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: Datasnap REST XE4 and Heavyweight Callbacks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 9, 2017 4:33 AM   in response to: Júlio César Men... in response to: Júlio César Men...
Here is an example of how the test was implemented to execute the REST callback.

Server:
    test: = TJSONObject.Create;
    test.AddPair ('message', 'Some message');
    test.AddPair ('status', '1');
 
    DSServer.BroadcastMessage ('TestChannel', test);


Client JavaScript:
<html>
      <body>
            <button onClick = "test ()"> Request HTTP long polling </button>
            Home |
 
            <div>
              <font style="font-family: tahoma"> <b> Message: </b> </font> / font>
              Home
              <font style="font-family: tahoma"> <b> Status: </b> </font> / font>
            </div>
      
            <script src = "CallbackFramework.js"> </script>
            <script src = "connection.js"> </script>
            <script src = "ServerFunctionExecutor.js"> </script>
            <script src = "ServerFunctionInvoker.js"> </script>
            <script src = "ServerFunctions.js"> </script>
            <script src = "base64.js"> </script>
            <script src = "json2.js"> </script>
                                                         
            <script>
            
                    function test () {
                    
                      var channel = new ClientChannel (null, "TestChannel");
                      
                      console.log (channel);
                      
                      var callback = new ClientCallback (channel, null,
                        function (jsonValue) {
                        
                          console.log (jsonValue);
                          
                          if (jsonValue! = null) {
                          
                            if ("message" in jsonValue) {
                              document.getElementById ("message"). innerHTML = jsonValue.message;
                            }
                            
                            if ("status" in jsonValue) {
                              document.getElementById ("status"). innerHTML = jsonValue.status;
                            }
                          }
                          
                          return true;
                          
                      });
                      
                      channel.connect (callback);
                             
                    }
            </script>
      </body>
</html>
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: Datasnap REST XE4 and Heavyweight Callbacks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2017 5:43 AM   in response to: Júlio César Men... in response to: Júlio César Men...
Guys, nothing?
No one dares to make any suggestions?

I've been studying the subject and discovered two more "technologies" for this: WebSocket and Server-Sent Events, but both are not available in all browsers.

It seems, HTTP long polling is conservative but works on everyone!
Júlio César Men...

Posts: 14
Registered: 3/20/09
Re: Datasnap REST XE4 and Heavyweight Callbacks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2017 5:00 AM   in response to: Júlio César Men... in response to: Júlio César Men...
Hi,

Solved! Thanks.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02