Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Francois Piette
 What I'm doing wrong?

Your HTTP component runs in the main thread since you created in the context
of the main thread (TThread constructor execute in the context of the
calling thread, not in the context of the created thread). Create you HTTP
component instance from the thread's Execute method and free it at the end
of the Execute method. Don't forget to have a message pump within your
Execute method also. Look at the multithread sample programs delivered with
ICS. See their creation date. Generally to more recent the better they are.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be


- Original Message - 
From: Anatoly Podgoretsky [EMAIL PROTECTED]
To: TWSocket List twsocket@elists.org
Sent: Thursday, October 05, 2006 10:05 PM
Subject: [twsocket] How to use THttpCli with threads?


 Hi!

 I want use THttpCli within TTread, but when I close application it
eception with AV at address 0
 Code follow

 constructor TBaseThread.Create;
 begin
   inherited Create(False);
   FreeOnTerminate := True;
   HttpClient  := THttpCli.Create(nil);
 {
   HttpClient.Agent  := 'Anatoly Podgoretsky NNTP Server';
   HttpClient.MultiThreaded  := True;
 }
 end;

//**

 // разрушение базового потока

//**

 destructor TBaseThread.Destroy;
 begin
   HttpClient.Free;
   inherited;
 end;

 What I'm doing wrong?
 Thread do nothing with main thread, this code only for testing. Real will
written in future

 With best regards,
 Anatoly Podgoretsky


 -- 
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Arno Garrels
Hello,

With  your code below THttpCli's events are not executed in TBaseThread.
Create and Destroy THttpCli in Execute procedure of the thread.

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html


Anatoly Podgoretsky wrote:
 Hi!
 
 I want use THttpCli within TTread, but when I close application it
 eception with AV at address 0 Code follow
 
 constructor TBaseThread.Create;
 begin
   inherited Create(False);
   FreeOnTerminate := True;
   HttpClient  := THttpCli.Create(nil);
 {
   HttpClient.Agent  := 'Anatoly Podgoretsky NNTP Server';
   HttpClient.MultiThreaded  := True;
 }
 end;
 //**
 // ??  ??
 //**
 destructor TBaseThread.Destroy;
 begin
   HttpClient.Free;
   inherited;
 end;
 
 What I'm doing wrong?
 Thread do nothing with main thread, this code only for testing. Real
 will written in future 
 
 With best regards,
 Anatoly Podgoretsky
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Anatoly Podgoretsky
Hi Arno and Francois,

I understood my my mistake. I think that TBaseThread.Create is thread context 
and it is wrong.
I found another decision. Nnow I create HtthCli before creating TBaseThread and 
put reference of it in TBaseThread.create. When TBaseThread terminate I free 
instanse of HtthCli in OnTerminate Event handler/
I 'll look for multithread sample programs for better understanding a 
technology.

What about TBaseThread.Destroy in wich context it execute? In context of thread?

With best regards,
Anatoly Podgoretsky

- Original Message - 
From: Francois Piette [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Friday, October 06, 2006 10:11 AM
Subject: Re: [twsocket] How to use THttpCli with threads?


 What I'm doing wrong?
 
 Your HTTP component runs in the main thread since you created in the context
 of the main thread (TThread constructor execute in the context of the
 calling thread, not in the context of the created thread). Create you HTTP
 component instance from the thread's Execute method and free it at the end
 of the Execute method. Don't forget to have a message pump within your
 Execute method also. Look at the multithread sample programs delivered with
 ICS. See their creation date. Generally to more recent the better they are.
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Arno Garrels
Component events are executed in worker thread context ONLY IF they
are either created in the Execute procedure or if you use methods
ThreadDetach/ThreadAttach instead. The hidden window of a ICS
component must be created in worker thread context.
TThread.Create is executed in the calling thread.

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html


Anatoly Podgoretsky wrote:
 Hi Arno and Francois,
 
 I understood my my mistake. I think that TBaseThread.Create is thread
 context and it is wrong. I found another decision. Nnow I create
 HtthCli before creating TBaseThread and put reference of it in
 TBaseThread.create. When TBaseThread terminate I free instanse of
 HtthCli in OnTerminate Event handler/ I 'll look for multithread
 sample programs for better understanding a technology.   
 
 What about TBaseThread.Destroy in wich context it execute? In context
 of thread? 
 
 With best regards,
 Anatoly Podgoretsky
 
 - Original Message -
 From: Francois Piette [EMAIL PROTECTED]
 To: ICS support mailing twsocket@elists.org
 Sent: Friday, October 06, 2006 10:11 AM
 Subject: Re: [twsocket] How to use THttpCli with threads?
 
 
 What I'm doing wrong?
 
 Your HTTP component runs in the main thread since you created in the
 context of the main thread (TThread constructor execute in the
 context of the calling thread, not in the context of the created
 thread). Create you HTTP component instance from the thread's
 Execute method and free it at the end of the Execute method. Don't
 forget to have a message pump within your Execute method also. Look
 at the multithread sample programs delivered with ICS. See their
 creation date. Generally to more recent the better they are. 
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Francois Piette
 I found another decision. Nnow I create HtthCli before creating
 TBaseThread and put reference of it in TBaseThread.create.

There is another issue you seems to ignore. A thread context is not related
at all to the TThread class. It is not because you run a TThread method that
it runs within the conext of the thread created by the TThread class !

A method is executed in the context of a thread only if it is called from
the Execute method (or any method called directly or indirectly by that
execute method). You can have any thread calling any method in a TThread
class instance but then the method is executed within the context of the
CALLING thread, not the context of the thread created by the class.

Speaking ICS components and events, the events are executed in the thread
context which CREATED the component (or the thread attached using
ThreadAttach method). No matter where the event handler is defined. This is
how Windows works.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be


- Original Message - 
From: Anatoly Podgoretsky [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Friday, October 06, 2006 9:46 AM
Subject: Re: [twsocket] How to use THttpCli with threads?


 Hi Arno and Francois,

 I understood my my mistake. I think that TBaseThread.Create is thread
context and it is wrong.
 I found another decision. Nnow I create HtthCli before creating
TBaseThread and put reference of it in TBaseThread.create. When TBaseThread
terminate I free instanse of HtthCli in OnTerminate Event handler/
 I 'll look for multithread sample programs for better understanding a
technology.

 What about TBaseThread.Destroy in wich context it execute? In context of
thread?

 With best regards,
 Anatoly Podgoretsky

 - Original Message - 
 From: Francois Piette [EMAIL PROTECTED]
 To: ICS support mailing twsocket@elists.org
 Sent: Friday, October 06, 2006 10:11 AM
 Subject: Re: [twsocket] How to use THttpCli with threads?


  What I'm doing wrong?
 
  Your HTTP component runs in the main thread since you created in the
context
  of the main thread (TThread constructor execute in the context of the
  calling thread, not in the context of the created thread). Create you
HTTP
  component instance from the thread's Execute method and free it at the
end
  of the Execute method. Don't forget to have a message pump within your
  Execute method also. Look at the multithread sample programs delivered
with
  ICS. See their creation date. Generally to more recent the better they
are.
 -- 
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Anatoly Podgoretsky
I ask before about

1. What I set to property Multitreaded? I don't understand it.
I did? I believe I must.

and about

3. In all examples I see that I must access HttpCli data with Memory Stream 
(ms.LoadFromStream(StringList) - is another method to access received data 
without a stream? Directly. Like HttpCli.Get, HttpCli.Body.

It isn't?

With best regards,
Anatoly Podgoretsky
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Abdullah AlQasim
I think the best way Francois provide us a full multi-threading  example 
for HttpCli or any member in the list already done sample for that.


Anatoly Podgoretsky wrote:
 I ask before about

 1. What I set to property Multitreaded? I don't understand it.
 I did? I believe I must.

 and about

 3. In all examples I see that I must access HttpCli data with Memory Stream 
 (ms.LoadFromStream(StringList) - is another method to access received data 
 without a stream? Directly. Like HttpCli.Get, HttpCli.Body.

 It isn't?

 With best regards,
 Anatoly Podgoretsky
   

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Frans van Daalen

- Original Message - 
From: Abdullah AlQasim [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Friday, October 06, 2006 3:51 PM
Subject: Re: [twsocket] How to use THttpCli with threads?


I think the best way Francois provide us a full multi-threading  example
 for HttpCli or any member in the list already done sample for that.


like HttpThrd which is a http thread demo and available in the demo 
directory ??? 

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Anatoly Podgoretsky
Hi Frans,

Examples and third party demos are very high, really I don't catch all of them. 
:-)

But I looked its example and see that my current code very similar.

With best regards,
Anatoly Podgoretsky

- Original Message - 
From: Frans van Daalen [EMAIL PROTECTED]

I think the best way Francois provide us a full multi-threading  example
 for HttpCli or any member in the list already done sample for that.

 
 like HttpThrd which is a http thread demo and available in the demo 
 directory ??? 
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Anatoly Podgoretsky
Thanks Abdullah,

Now I look HttpThr example

With best regards,
Anatoly Podgoretsky



- Original Message - 
From: Abdullah AlQasim [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Friday, October 06, 2006 4:51 PM
Subject: Re: [twsocket] How to use THttpCli with threads?


I think the best way Francois provide us a full multi-threading  example 
 for HttpCli or any member in the list already done sample for that.
 
 
 Anatoly Podgoretsky wrote:
 I ask before about

 1. What I set to property Multitreaded? I don't understand it.
 I did? I believe I must.

 and about

 3. In all examples I see that I must access HttpCli data with Memory Stream 
 (ms.LoadFromStream(StringList) - is another method to access received data 
 without a stream? Directly. Like HttpCli.Get, HttpCli.Body.

 It isn't?

 With best regards,
 Anatoly Podgoretsky
   
 
 -- 
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to use THttpCli with threads?

2006-10-06 Thread Francois Piette
 1. What I set to property Multitreaded? I don't understand it.

This property tells the component it is working within a secondary thread.
See the source code and you'll see it use that property to slightly modify
the way it get and handle messages.

 3. In all examples I see that I must access HttpCli data with Memory
Stream (ms.LoadFromStream(StringList) - is another method to access received
data without a stream? Directly. Like HttpCli.Get, HttpCli.Body.

No. Use the stream. A document returned by HTTP could be very large. Asking
the component to store it internally would make it both slower and limited
in size. Using a stream (that is just an interface) allow you to select the
best way to handle it. Either with an existing TSream derived class
(TFileStream for disk storage, TMemoryStream for in memory storage,...) or
any derived class you can write (for example to handle the received document
on the fly as IE do).

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] How to use THttpCli with threads?

2006-10-05 Thread Anatoly Podgoretsky
Hi!

I want use THttpCli within TTread, but when I close application it eception 
with AV at address 0
Code follow

constructor TBaseThread.Create;
begin
  inherited Create(False);
  FreeOnTerminate := True;
  HttpClient  := THttpCli.Create(nil);
{
  HttpClient.Agent  := 'Anatoly Podgoretsky NNTP Server';
  HttpClient.MultiThreaded  := True;
}
end;
//**
// разрушение базового потока
//**
destructor TBaseThread.Destroy;
begin
  HttpClient.Free;
  inherited;
end;

What I'm doing wrong?
Thread do nothing with main thread, this code only for testing. Real will 
written in future

With best regards,
Anatoly Podgoretsky


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Re: [twsocket] How to use THttpCli with threads?

2006-10-05 Thread Anatoly Podgoretsky
Hi all,

I carefully reread a FAQ and see other scenario.
Divide process into two pieces, download information from WEB site into main 
thread (ClientConnection) and run thread after data received only for database 
work.

My application is NNTP server with downloading information from one site, put 
it into database and news client get this information from database.

Client ask NNTP server for information, standard protocol. 
Server get request and ask information from database, then immediatelly reply 
to clent.
After it, server dynamically create some HttpCli and start downloading in 
asynchronous mode.
When In OnRequestDone server start a one or more individual threads only for 
heavy load database work. 
Thread do not cooperate with main thread, except OnTerminate Event.
During this operation client can ask other piece of information and this 
operation can start simultaneosy with paralel downloading a data and operating 
with database.

It is a right way? May be is other decision?

And now I have some questions:

1. What I set to property Multitreaded? I don't understand it.

2. Where and when I can destroy HttpCli
   a. In Event Handler OnRequestDone event, I think it's bad idea because it's 
a Event handler of HttpCli.
   b. I can send a user message itself, but how I can decide witch HttpCli I 
must destroy HttpCli.
   c. Destroy HttpCli on OnTerminate a thread.
   d. Destroy HttpCli on each Client request checking witch HttpCli is ready 
for destroy

3. In all examples I see that I must access HttpCli data with Memory Stream 
(ms.LoadFromStream(StringList) - is another method to access received data 
withou a stream? Directly. Like HttpCli.Get, HttpCli.Body.

I need your opinion about this scheme, how it right, another decision with 
simultaneously multi downloading from site and operate with received data with 
threads.

With best regards,
Anatoly Podgoretsky

- Original Message - 
From: Anatoly Podgoretsky [EMAIL PROTECTED]

 I want use THttpCli within TTread, but when I close application it eception 
 with AV at address 0
 Code follow
 
 constructor TBaseThread.Create;
 begin
  inherited Create(False);
  FreeOnTerminate := True;
  HttpClient  := THttpCli.Create(nil);
 {
  HttpClient.Agent  := 'Anatoly Podgoretsky NNTP Server';
  HttpClient.MultiThreaded  := True;
 }
 end;
 //**
 // разрушение базового потока
 //**
 destructor TBaseThread.Destroy;
 begin
  HttpClient.Free;
  inherited;
 end;
 
 What I'm doing wrong?
 Thread do nothing with main thread, this code only for testing. Real will 
 written in future
 
 With best regards,
 Anatoly Podgoretsky
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be