#1 2013-07-01 19:05:39

Kobe
Member
Registered: 2013-04-08
Posts: 38

Connection through thread

Hello,

I need to make the connection between client and server happens through a thread, besides the main application thread, because sometimes the connection may take longer than normal and the application freezes for a few seconds waiting for the end of the connection.

What better way to do this? Is there another way to solve this freezing?

Thanks.

Offline

#2 2013-07-01 19:49:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

You can use several client connections, one per per thread.

But you can also use a background thread on the server side, if some process takes time.

Offline

#3 2013-07-01 20:57:30

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

The thread that I'm talking about would be on the client side, can I use a thread to connect?

Offline

#4 2013-07-02 04:30:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Yes, with a given client instance.

Offline

#5 2013-07-02 11:40:57

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

OK, how can I make to force the client to create a new thread, on the client side, to connect to the server?

Last edited by Kobe (2013-07-02 11:41:30)

Offline

#6 2013-07-02 13:56:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

There is no way of doing it in the current client implementation.

You have to create your own TThread sub class, the use a dedicated client instance in its Execute method.

Offline

#7 2013-07-02 14:17:36

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

Would the new class should work over the TSQLHttpClient class?

Do you think a implementation like this can be good to the mORMot project, working as a option to the current implementation?

Last edited by Kobe (2013-07-02 14:19:12)

Offline

#8 2013-07-02 17:22:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

You mean having an asynchronous mode from the main thread, or using a dedicated thread for background process?

Offline

#9 2013-07-02 17:34:21

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

Yes
Does that make any sense for the mORMot project?

Last edited by Kobe (2013-07-02 17:34:53)

Offline

#10 2013-07-02 19:42:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

This is just a way of making the client more fluid.

Offline

#11 2013-07-02 20:32:09

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

Wich is better to solve the freezing problem: the asynchronous mode or the edicated thread for background process?

How can I help you on this development? I'm not as wise as you're on Delphi development.

Offline

#12 2013-07-02 20:34:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Asynchronous mode is very tempting...

Offline

#13 2013-07-02 22:18:03

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

How would work this Asynchronous mode?

Offline

#14 2013-07-03 09:13:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Either with an overriden TSQLRestClient.URI() which will allow calling a custom property during waiting (e.g. for Application.ProcessMessage), and use a background thread during the blocking communication.

Or with a dedicated "tasker" - new TTask class which may be also needed for implement future event-driven programming - http://blog.synopse.info/post/2012/09/0 … laboration

Offline

#15 2013-07-03 12:01:41

KJames
Member
Registered: 2013-07-02
Posts: 15

Re: Connection through thread

ab wrote:

...and use a background thread during the blocking communication.

What would be the function of this background thread?

Offline

#16 2013-07-03 13:09:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

KJames wrote:

What would be the function of this background thread?

... doing the blocking communication itself, without blocking the main thread, so the main UI.

You have several options, e.g.
- the microsoft Task class - http://msdn.microsoft.com/en-us/library … .task.aspx
- the RemObject asynchronous call - http://wiki.remobjects.com/wiki/Asynchr … K_(Delphi)
- Or just allow to run an "idle" method e.g. to run Application.ProcessMessage, display a popup window if times is noticeable, and/or allow request cancel.

Perhaps the 3rd could be OK..

Offline

#17 2013-07-03 14:33:31

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

I believe the 2nd may be the better option, and can solve this feature request: http://synopse.info/fossil/info/68337ae98a

Offline

#18 2013-07-03 15:22:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Kobe wrote:

I believe the 2nd may be the better option, and can solve this feature request: http://synopse.info/fossil/info/68337ae98a

But I'm still not convinced about the "exploded" new interface in such case.

If the purpose is only to let the UI interact properly as expected, the 3rd solution is clean & enough.
This is what I will do in the short term - prepared by http://synopse.info/fossil/info/a5ae673869 latest commit, in fact.

Then event-driven publish/subscribe methods will probably a better option than this RemObjects' "exploded" interfaces.

Offline

#19 2013-07-03 16:52:28

Kobe
Member
Registered: 2013-04-08
Posts: 38

Re: Connection through thread

You are totally right. I was testing and the connection got a little bit faster too, is that related to this change too?

Offline

#20 2013-07-03 17:42:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Kobe wrote:

I was testing and the connection got a little bit faster too, is that related to this change too?

I do not think so, honestly...
smile

Offline

#21 2013-07-04 13:00:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Connection through thread

Offline

Board footer

Powered by FluxBB