RTC Forums
November 25, 2024, 12:14:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Streaming headlines...  (Read 6900 times)
trendready
RTC Expired
*
Posts: 1


« on: December 15, 2009, 07:39:16 PM »

Danijel,

I am currently using TRtcHttpServer to provide data to several apps written in Visual C++ and .net.  Is there a way I can send data (like a news headline feed) to the apps without them polling the server?   My RTCHttpServer is replacing a open socket connection.

New topic.. this implementation of your forum has several editing icons/options above this edit box.  How do I add them to your sample forum app?

Thanks in advance.

Paul Di Biasio

Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: December 15, 2009, 07:57:50 PM »

Hi,

1) A HTTP Server always waits for Clients to ask for data (it serves the clients). It will never send data out to clients without being asked for it. To use a HTTP Server for providing data to Clients, your Clients will have to ask the Server for data (poll). This is simply how HTTP Clients and Servers are designed to work.

2) The current Forum implementation is NOT written in Delphi, nor is it hosted on the RTC WebServer. The Forum you are currently using here is called "SimpleMachines" and can be downloaded from http://www.simplemachines.org

Best Regards,
Danijel Tkalcec
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 on: December 15, 2009, 08:32:22 PM »

Btw ... if you want to reduce the traffic generated when polling the Server for data, and your Clients are using RTC remote functions (should also work with XML-RPC, although I haven't tested it), you should take a closer look at "PrepareDelayedCall", "PostDelayedCall" and "CancelDelayedCall" functions and the TRtcDelayedCall class, all of which are available in the "rtcSrvModule.pas" unit. This is called "Delayed Calls" in RTC SDK and here is a general explanation on how Delayed Calls work with the RTC SDK ...

If you want your server to be able to send the data to your client when server wants, there is nothing special you need to do on the client side, except call a remote function and know that a result will come when there is data available, or when a time limit is expired.

After client receives a result (any kind), it should use a timer to post another call, to keep a connection open all-the-time at the server.

On the server side, you use PrepareDelayedCall from within your remote function’s OnExecute event to prepare a call and get an object, which you can use to wake the call later. Then, you use PostDelayedCall to go to a “sleep state”, which will be “broken” after the timeout expires (specified by using PrepareDelayedCall) or if you call the “WakeUp” method on the object you obtained from PrepareDelayedCall.

Using PrepareDelayedCall and PostDelayedCall is not complicated, but it could be a bit “tricky” if you want to be able to “wake the delayed call”, since you will have to store a temporary object and use if from somewhere else in your application.

I guess, the best place to start learning about using delayed calls with RTC SDK is looking at RTC Messenger Server’s remote function for “get msg”. Also, check the description for the TRtcDelayedCall class and description of PrepareDelayedCall, PostDelayedCall and CancelDelayedCall functions.

Here's another explanation ...

Your client can send remote calls to the Server to ask if the Server has something for the Client. The Client side is simple here. You can either use a timer to periodicaly issue a remote call, or ... you can send the next call from the OnResult event of your TRtcResult object. Either way, you will have an endless loop on the client side.

On the Server side, you can use DelayedCalls to enable the Server to respond when it has something to send. Using DelayedCalls, Server will put the remote function "to sleep" by specifying a timeout (after which the function will be "awaken" automaticaly) and getting an object using which you can wake the function up (when you got data to send back to the client).

Generaly, to implement the DelayedCalls approach, your Client will repeatedly send a remote call to the Server, Server will check if there is something it wants to send to the Client and if not, put the call to sleep, then (from your functions which prepare the data for your clients) wake the call up to signal that it has something to send to the Client.

RTC Messenger uses this approach to implement message dispatching between clients. This way, when a client sends a message to another client, it will be delivered instantly, even though clients are triggering "Get Message" calls once every 30 seconds (to avoid flooding the network).

And here is the explanation for individual functions and classes in use ...

** TRtcDelayedCall = class(TRtcObject)
- Delayed Function Call object: This object is returned from the PrepareDelayedCall function and can be used to Wake up the delayed call. The only method you are allowed to use on this object is "WakeUp", and this one may only be called once, after which you have to "forget" about that object (set your variable's pointer to NIL), so you don't go and call it often.

** function PrepareDelayedCall(msDelay:integer; Param:TRtcFunctionInfo; Event:TRtcFunctionCallEvent):TRtcDelayedCall;
- Prepare a function call to "Event" using "Param" paremeters, which should be delayed for "msDelay" miliseconds.   Use "PostDelayedCall" with the object returned from PrepareDelayedCall (TRtcDelayedCall) to post this call. You can also use the Result (TRtcDelayedCall) to execute the delayed call sooner (from any thread) by calling "TRtcDelayedCall.WakeUp". You can NOT CANCEL THE CALL after you have Posted it with PostDelayedCall. If connection should get lost while a Delayed Call is waiting, delayed call will be canceled automaticaly. If you need to make any changes to the parameters passed to the delayed call, you have to do it BEFORE using PrepareDelayedCall, because PrepareDelayedCall creates a copy of all parameters and any change to the original Params will not be reflected in that copy later.

** procedure PostDelayedCall(cb:TRtcDelayedCall); overload;
- Post delayed call which was prepared using PrepareDelayedCall. You can use the Result (TRtcDelayedCall) to execute the delayed call sooner (from any thread) by using the "TRtcDelayedCall.WakeUp" method. You can NOT CANCEL THE CALL after you have Posted it by using PortDelayedCall, you can only Wake it up sooner. If connection should get lost while a Delayed Call is waiting, delayed call will be canceled automaticaly.

** procedure CancelDelayedCall(cb:TRtcDelayedCall);
- If you prepared a delayed call, but do not want to Post it anymore, use this procedure to cancel it before calling PostDelayedCall. DO NOT CALL THIS PROCEDURE AFTER YOU HAVE POSTED THE CALL!!!! You can NOT CANCEL THE CALL after you have Posted it (with PostDelayedCall). If connection should get lost while a Delayed Call is waiting, delayed call will be canceled automatically.

PS. One example where Delayed calls are being used is the RTC Messenger Client and Server. Another example is Nexus Portal, where Delayed calls are being used on the Portal Gateway is serving as a hub between Portal Hosts, Viewers and Controls.

Best Regards,
Danijel Tkalcec
Logged
kaju74
Newbie
*
Posts: 25


« Reply #3 on: December 17, 2009, 06:07:09 PM »

Hi...

YFI:

I want to try the "RTC_Messenger" - Example, but this demo couldn't be compiled without errors in class "URxRichEd".

Regards,
Marc
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 on: December 18, 2009, 01:23:17 AM »

Thank you for your feedback.

I have now released an update for the RTC SDK (v3.42) which will fix the Messenger Client Demo project (among other things). Updated Messenger Client Demo does NOT use third-party components anymore (RxRichEdit was used before), it now has full Unicode support when compiled with Delphi 2009 and later, and is compatible with all Delphi versions from D6 to D2010.

To get the updated RTC Messenger project files, please download the RTC SDK 3.42 (or later) from the "RTC SDK PRO Downloads" area. Should you have any other problems with example projects included in the RTC SDK package, please let me know. All RTC SDK demo and quick start projects should now compile and work with Delphi 6 - 2010.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.027 seconds with 16 queries.