RTC Forums
November 23, 2024, 05:56:44 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Proper usage of TRtcMessageServer and TRtcMessageClient in one exe  (Read 7717 times)
Max Terentiev
RTC License
***
Posts: 49


« on: August 31, 2016, 07:54:09 PM »

Hi Danijel,

I noitce problems with TRtcMessageServer/TRtcMessageClient:

I have Form1 with

RtcMessageClient
RtcClientModule
RtcResult

and Form2 with

RtcMessageServer
RtcServerModule
RtcFunctionGroup
RtcFunction

Form1.RtcMessageClient.Server:=Form2.RtcMessageServer;
Form1.RtcMessageClient.AutoConnect:=true;

I can call remote function using Form1.RtcClientModule.Prepare/Call and receive reply with no problems. But after closing test app FastMM reports AV in TRtcConnection.ReleaseProvider
and lots of memory leaks.

In Form1.FormCloseQuery i write:

if (RtcMessageClient.DisconnectNow=wait_ok) and (Form2.RtcMessageServer.StopListenNow=wait_OK) then
    CanClose:=true

But I got AV anyway (

Maybe I use components in wrong way ? I need to implement "local transport" mode (without listening any network port) in single .exe. I use TRtcMessageClient and TRtcMessageServer as you suggested.

p.s. Delphi 10.1 Berlin, Win32.

Thanks for help !

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


« Reply #1 on: September 01, 2016, 06:17:56 AM »

1. "CanClose" is True by default in the OnCloseQuery event. You need to change it to False if the App can not be closed.

2. Before disconnecting the Client, set AutoConnect:=False on the Client component.

3. After disconnecting the Client, set Server:=nil on the Client component.

Let me know if that helped.

P.S. When you directly attach a MessageServer to a MessageClient using its Server property, the Server component is basically a "transport" for the Client. In that scenario, the Client is directly executing methods on the Server and the Server is directly calling methods on the Client when they communicate. In fact, the two components act as one in that case. Destroying one of the components without removing a link to the other component is a guarantee for trouble.

Best Regards,
Danijel Tkalcec
Logged
Max Terentiev
RTC License
***
Posts: 49


« Reply #2 on: September 01, 2016, 10:34:54 AM »

Sorry, but it's not helps. Still same errors.

Here is sample project to reproduce problem: http://www.bspdev.ru/AvTest.zip

And one question: if RtcMessageServer.MultiThreaded:=true and I use it for local transport (RtcMessageClient.Server:=RtcMessageServer) is remote functions will be executed in threads like in "real" RtcHttpServer ? This important for me because I want to use same code base for "local" and http transports.

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


« Reply #3 on: September 01, 2016, 09:51:30 PM »

There were some issues with "TRtcMessageClient" and "TRtcMessageServer" component destructors in Multi-Threaded mode.
Please, download the latest RTC SDK update (v7.37 - just released) and let me know if everything works now.

It should be enough now to use DisconnectNow on the Client and StopListenNow on the Server before closing the Application to avoid exceptions and memory leaks. For example, like this (if used from the OnCloseQuery event in you example Project):

CanClose:=(RtcMessageClient.DisconnectNow=wait_ok) and (Form2.RtcMessageServer.StopListenNow=wait_OK);

Best Regards,
Danijel Tkalcec
Logged
Max Terentiev
RTC License
***
Posts: 49


« Reply #4 on: September 02, 2016, 12:35:08 PM »

It's works now ! Thank you very much for the fix !

And please answer this question:

if RtcMessageServer.MultiThreaded:=true and I use it for local transport (RtcMessageClient.Server:=RtcMessageServer) is remote functions will be executed in threads like in "real" RtcHttpServer ? This important for me because I want to use same code base for "local" and http transports.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 on: September 02, 2016, 03:17:50 PM »

The same way a RtcHttpClient compoment uses a background thread when MultiThreaded:=True, RtcMessageClient component will also use a background thread for everything you do with the component.

As for the RtcMessageServer component, when it is directly assigned to the RtcMessageClient's Server property, it only acts as a direct transport, which will be used directly by the RtcMessageClient component to execute code from inside that Clients thread.

In short, every RtcMessageClient component will have a virtual thread of its own (from the rtc theead pool) to execute its calls if you set its MultiThreaded property to TRUE.

Best Regards,
Danijel Tkalcec
Logged
Max Terentiev
RTC License
***
Posts: 49


« Reply #6 on: September 02, 2016, 09:57:41 PM »

Thank you very much ! Your support is great )
Logged
jamesinform
RTC License
***
Posts: 4


« Reply #7 on: September 21, 2017, 11:27:43 AM »

Is it possible to link a rtcHTTPClient directly to a rtcHTTPServer (transparent)?

If so, how to do it?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #8 on: September 21, 2017, 11:39:35 AM »

TRtcHttpClient and TRtcHttpServer components are using HTTP over TCP/IP, which means that the Server requires a TCP/IP Port to listen to and the Client requires a TCP/IP Port to connect to. What would be the purpose of "linking" these two components?

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 17 queries.