I need to send multiple simultaneous HTTP requests to different servers.
I need to know if the following approach is correct, or if there's another (recommended) way of doing this:
1. For each connection, I create a TRtcHttpClient (Multithreaded = True) and TRtcDataRequest object. (The documentation says to use TRtcHttpClient.New/Release instead of Create/Free, but the Data Request object has no such methods, so I assume I can use TRtcDataRequest.Create(nil)?
In another thread (
HERE), you mentioned this:
>>3) The comment about using New and Release instead of Create and Free are actually relics from the past, when I was thinking about making the RTC SDK compile cross-compatible with Delphi.NET. You can safely ignore them now.
If this is true, then why is it still prominent in the help file?
2. I create a single set of event handlers, which get assigned to each new connection/data request instance (e.g., RtcHttpClient.OnConnect := TForm1.ClientConnect, RtcHttpDataRequest.OnBeginRequest := TForm1.DataRequestBeginRequest, etc.)
3. When sending the request, I set the ServerAddr & PortAddr for the connection and then call it's corresponding RtcDataRequest.Post() method.
- Before calling RtcDataRequest.Post(), I assign the data to the connection:
RtcHttpClient.Info.asString['Data'] := <string data>;
- In the BeginRequest() event, I attempt to receive the data, but only get an empty/null string in return (I've confirmed that <string data> is not empty):
Data := Cli.Info.asString['Data'];
What am I doing wrong here?
4. After I process the message and get a response, I want to disconnect the connection, then delete/free the RtcHttpClient & RtcDataRequest instance (or return them to a pool I created for reuse). At what point is it safe to do this? In addition, when disposing, can I call RtcDataRequest.Free and then RtcHttpClient.Release? The AppClient demo has code that does this, but states:
// We are releasing all connection components.
// This will free them from memory,
// without calling "OnDisconnect".
// This is something that you should NOT do
// from a normal client application.
So I need to know the correct way of disposing of them or knowing when they are no longer in use so I can return them to the pool.
5. On another note, I understand the concept of a Job, but didn't find any examples that used them. If I post a job to a connection, how does the job actually send data on the connection?
Thanks,
Doug