RTC Forums

Subscription => Support => Topic started by: ISIGest on November 06, 2014, 11:27:40 AM



Title: Connect, login and post first request
Post by: ISIGest on November 06, 2014, 11:27:40 AM
Hi,
I've an HttpClient (HTTPCli), a ClientModule (CliModule) and 2 function result (resLogin, resGetData)
I need to post a request function "GetData" after connected and logged in (after resLogin)
What is the best way to do this by calling a single procedure.


Title: Re: Connect, login and post first request
Post by: D.Tkalcec (RTC) on November 06, 2014, 11:38:37 AM
If you don't mind using AutoSessions, you can set the AutoLogin property on the TRtcClientModule component to TRUE, implement the OnLogin event to prepare the "resLogin" function call and implement the OnLoginResult events to handle the result from the login function. Then, you won't have to manually call the "resLogin" function. It will be called automatically when a new Session is created, before any other remote function calls is sent to the Server. So ... after you have the AutoLogin feature enabled and the OnLogin/OnLoginResult events implemented, calling any remote function (like "resGetData") in your code will result in sending the "resLogin" call first.

You can also make new non-blocking (event-driven) remote function calls from inside the OnResult events triggered by previous remote function calls by using the Call method. Simply include the Senter:TRtcConnection as a parameter when using the Call method inside the OnResult event, to make sure the same connection object will be used to post that remote call. But do NOT use the Execute method from RTC events, because that would result in circular event calls and could freeze the Application.

Best Regards,
Danijel Tkalcec


Title: Re: Connect, login and post first request
Post by: ISIGest on November 06, 2014, 11:47:30 AM
On the server, how can I manager the AutoLogin?


Title: Re: Connect, login and post first request
Post by: D.Tkalcec (RTC) on November 06, 2014, 11:53:44 AM
On the Server side, simply set the AutoSessions property to TRUE on the TRtcServerModule component and implement the "resLogin" function like any other remote function. What you do in that function depends only on your login requirements. With AutoSessions enabled, a new Session will be opened automatically by the component if it does not exist and you will have access to the Session property on the Server from the OnExecute event through the Sender:TRtcDataServer parameter sent to the event, on all TRtcFunction components linked to the TRtcFunctionGroup connected to that TRtcServerModule component.

The use of automatic Sessions with remote functions is explained in the Quick Start lessons (https://rtcforum.teppi.net/index.php?topic=311.0).

Best Regards,
Danijel Tkalcec


Title: Re: Connect, login and post first request
Post by: ISIGest on November 06, 2014, 11:57:18 AM
What is the Event (On the server) to manage the autologin reqeust by client?


Title: Re: Connect, login and post first request
Post by: D.Tkalcec (RTC) on November 06, 2014, 12:00:12 PM
There is no special event for that on the Server. The Client will make a normal remote function call to the Server, based on your OnLogin event implementation. The Server will handle your "login" function call like any other remote function call, so you can call any function you want on the Server to handle logging in. You just need to implement the function using the TRtcFunction component, like you would implement any other remote function.

If you need a working example, take a look at the RTC Messanger Demo.

Best Regards,
Danijel Tkalcec


Title: Re: Connect, login and post first request
Post by: ISIGest on November 06, 2014, 12:06:07 PM
I don't understand:

--> "Client"
I implement in OnLogin event of TRtcClientModule a code like this:

Data.NewRecord.asString['Pass'] := 'myPassword';

and handle the result in OnLoginResult event to check if the login is ok...

---> "Server"
How can I check if the password is wrong or not??


Title: Re: Connect, login and post first request
Post by: D.Tkalcec (RTC) on November 06, 2014, 12:12:17 PM
No. On the Client side, in the OnLogin event, you need to create the Remote Function object and not a simple record.

Like this:

--> "Client" in the OnLogin event ...

Data.NewFunction('resLogin');
Data.asFunction.asString['User'] := 'myUsername';
Data.asFunction.asString['Pass'] := 'myPassword';

--> "Server"

You need a TRtcFunction component with "resLogin" in the FunctionName property to handle the Function call which you have prepared in the "OnLogin" event on the Client side. It will be called like any other remote function on the Server, so it needs to be linked to the TRtcFunctionGroup, which is liked to the TRtcServerModule responsible for handling these remote functions.

Best Regards,
Danijel Tkalcec


Title: Re: Connect, login and post first request
Post by: ISIGest on November 16, 2014, 06:16:20 PM
I some also for autoping?


Title: Re: Connect, login and post first request
Post by: D.Tkalcec (RTC) on November 16, 2014, 07:10:50 PM
Yes. The AutoSessionsPing property works by using the OnPing event to prepare the PING remote call (just like the OnLogin event works to prepare the LOGIN call), the OnPingAborted event is called in case the PING call was aborted (just like the OnLoginAborted event would be called if a LOGIN call was aborted) and the OnPingResult event is called when the PING call receives a result from the Server (just like the OnLoginResult event is called when a result is received after a LOGIN call). The only difference is that LOGIN is executed only once for each new Session, while PING is being executed periodically in case of inactivity (no data sent nor received through the TRtcClientModule component) to keep the Session alive.

Best Regards,
Danijel Tkalcec