Thread: Datasnap REST XE4 and Heavyweight Callbacks
 |
This question is answered.
Helpful answers available: 2.
Correct answers available: 1.
|
|
Replies:
3
-
Last Post:
Oct 19, 2017 5:00 AM
Last Post By: Júlio César Men...
|
|
|
Posts:
14
Registered:
3/20/09
|
|
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!
|
|
|
Posts:
14
Registered:
3/20/09
|
|
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>
|
|
|
|
Posts:
14
Registered:
3/20/09
|
|
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!
|
|
|
|
Posts:
14
Registered:
3/20/09
|
|
|
|
|
Legend
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|
Connect with Us