Re: Nice odd tcpip socket question.
- From: Dodgy <Dodgy@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 May 2005 15:59:08 +0100
On Tue, 31 May 2005 13:45:39 +0000 (UTC), Marco van de Voort
<marcov@xxxxxxxx> waffled on about something:
>On 2005-05-31, Dodgy <Dodgy@xxxxxxxxxxxxxxxxxxxxx> wrote:
>> I'm trying to work with client sockets, done this loads of time
>> before, and happily use the Indy 9 components in D5 Ent.
>>
>> Today I hit a snag... The spec I have to conform to has fixed length
>> data packets, with no terminating character.
>>
>> I tried to use idtcpclient.readln, but I can't give it a termination
>> character, and it appears not to return anything until it finds the
>> termination character, even after the timeout has exceeded and it's
>> returned control to the app.
>>
>> I really need to be able to say "read x bytes, but give up waiting
>> after y seconds", something I though readln would do admirably. Alas
>> no. None of the other read methods allow a timeout to be set, and I
>> really need to keep this side under control as the eventual deployment
>> will be in a thread, and I don't want threads left laying about hung
>> because they have a tcpip connection, but for some reason the server
>> hasn't sent them the required number of bytes (i.e. the server process
>> has gone wrong).
>>
>> Any ideas?
>
>(untested) Readbuffer is
>
>procedure TIdTCPConnection.ReadBuffer(var ABuffer; const AByteCount: Integer);
>begin
> if (AByteCount > 0) and (@ABuffer <> nil) then begin
> // Read from stack until we have enough data
> while (InputBuffer.Size < AByteCount) do begin
> ReadFromStack;
> CheckForDisconnect(True, True);
> end;
> // Copy it to the callers buffer
> Move(InputBuffer.Memory^, ABuffer, AByteCount);
> // Remove used data from buffer
> InputBuffer.Remove(AByteCount);
> end;
>end;
>
>
>The readfromstack is the one that blocks, but it has default parameters that can adjust this behaviour.
>
>Iow derive from tidtcpconnection, add a "myreadbuffer" with the above code, but WITH timeout parameters for readfromstack.
Ah... actually I could just check the inputbuffer size before
attempting to read the data, so I can ensure I'm never asking for more
than I have.
Thanks for that, I'll go have a play
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
.
- References:
- Nice odd tcpip socket question.
- From: Dodgy
- Re: Nice odd tcpip socket question.
- From: Marco van de Voort
- Nice odd tcpip socket question.
- Prev by Date: Re: Nice odd tcpip socket question.
- Next by Date: Re: checking arbitrary bounds
- Previous by thread: Re: Nice odd tcpip socket question.
- Index(es):
Relevant Pages
|
|