I have finally got my Delphi application to send data using direct sockets with the Synapse library through HTTPS.
However, I am having trouble determining the size of the data being returned to me.
Currently, I have the following code:
Socket := TTCPBlockSocket.Create;
status := TStringList.Create;
status.Append('LineBuffer length: ' + IntToStr(Length(Socket.LineBuffer)));
status.Append('Waiting bytes: ' + IntToStr(Socket.WaitingDataEx));
status.Append('recvBufferStr: ' + CRLF + Socket.RecvBufferStr(240, 25000) );
status.Append('LastError = ' + Socket.LastErrorDesc);
status.Append('Error code: ' + IntToStr(Socket.LastError));
Memo1.Lines.AddStrings(status);
and I get the following in Memo1:
socket lastError = 0
LineBuffer length: 0
Waiting bytes: 0
recvBufferStr:
HTTP/1.1 200 OK
Date: Thu, 22 Dec 2011 01:06:07 GMT
Server: Apache
Content-Length: 237
Connection: close
Content-Type: text/plain; charset=utf-8
[***The returned Data***]
If Socket.RecvBufferStr's first parameter (length to receive) is too large, I get winsock error 10054 because i'm still waiting for data even though the server is done sending it.
If it is too short, which it almost always is, then I only get the specified amount of data.
Waiting bytes and linebuffer length show 0 (not sure if that's because they're longInt's and I'm doing IntToStr) so I don't think that's how I check the amount of data. And I have also tried using CanRead and CanReadEx to no avail.
I would like to do something like the following: Socket.RecvBufferStr([length to receive], [until all data is received] or 25000).
If there is another function, that is fine, but I would like to stick with TTCPBlockSocket as HTTPSend and others that I have tried from synapse do not work for my purposes.
How do I check - using the TTCPBlockSocket socket from the Synapse library with Delphi/Pascal - how much data the server is returning to me?