RTC Forums
November 25, 2024, 03:10:33 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
multiple results in multiple places
Pages: [
1
]
« previous
next »
Print
Author
Topic: multiple results in multiple places (Read 5145 times)
GeorgeK
Newbie
Posts: 7
multiple results in multiple places
«
on:
September 21, 2010, 01:08:32 AM »
I have code
RtcClientModule1.Prepare('MyFunction');
RtcClientModule1.Execute;
MyResult := RtcClientModule1.LastResult.AsString;
My problem is that this code may be executed from different places at the same time, so LastResult may conflict.
Is it safe to change it to:
RtcClientModule1.Prepare('MyFunction');
with RtcClientModule1.Execute do
MyResult := AsString;
to avoid conflict between different "Executes" inside app?
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: multiple results in multiple places
«
Reply #1 on:
September 21, 2010, 01:13:43 AM »
You can't use one blocking socket component from multiple threads at the same time. That's like trying to read and write to and from the same complex object from multiple threads at the same time which is a big no-no.
If you want to make remote calls on the Client from multiple threads at the same time, you will either need to do it non-blocking and implement events, or you will need a separate TRtcClientModule component per thread.
Best Regards,
Danijel Tkalcec
Logged
GeorgeK
Newbie
Posts: 7
Re: multiple results in multiple places
«
Reply #2 on:
September 21, 2010, 10:25:05 AM »
well, what I mean when I have two or more functions (different) and they will be called at the same time.
for example I have
HelloWorld function and HelloPeople.
If server execute both remote functions at the same time, what happens?
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: multiple results in multiple places
«
Reply #3 on:
September 21, 2010, 11:58:34 AM »
If you set
MultiThreaded to TRUE
on the TRtcHttpServer component and functions are called using different connection components (for example, from multiple clients or from the same client using multiple TRtcHttpClient components), then both functions will be executed at the same time. There is nothing special you need to do on either Client nor Server except making sure that your own code in the Server is thread-safe (for example, do not use a single global database connection component, but use a database connection pool or create and destroy components inside RTC events).
On the other hand, if you set MultiThreaded to FALSE on the TRtcHttpServer component, no matter how many clients call the Server at the same time all the calls will be executed one after another (serialized). In this case, your server-side code does not need to be thread-safe because there will always be only one thread running and there will be no concurrent access to your own Server-side code.
Best Regards,
Danijel Tkalcec
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...