Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Problem reading data from TidIOHandler

www.cryer.info
Managed Newsgroup Archive

Re: Problem reading data from TidIOHandler

Subject:Re: Problem reading data from TidIOHandler
Posted by:"Paul Nicholls" (paul_nicholls@hotmail.nospam.com)
Date:Tue, 15 Aug 2006 16:35:06

"Kiwi" <glen@custommadesoftware.co.nz> wrote in message
news:44e14282@newsgroups.borland.com...
>I am still having problems handling the data from the IOHandler
>
> This is the code on the Client Side.  The first 4 bytes that are recieved
> indicate the length of the stream.
> Here is the Server side code which seems to be working fine
>
>    fMem.Position:= 0;
>    Buf:= RawToBytes(fMem, fMem.Size);
>    I:= Length(Buf); // = 73050
>    SetLength(Buf, Length(Buf) +4);
>    Move(Buf[0], Buf[4], Length(Buf));
>    Move(I, Buf[0], 4); //90, 29, 1, 0
>    AContext.Connection.IOHandler.Write(Buf);
>
> Here is the Client side:
>      fMem:= TMemoryStream.Create;
>      try
>        SetLength(Buf, 0);
>        IOHandler.ReadBytes(Buf, 4, False);
>        Move(Buf[0], Size, 4);
>        if Size > 0 then
>          IOHandler.ReadBytes(Buf, Size, False);
>        fMem.Clear;
>        BytesToRaw(Buf, fMem, Size);
>        fMem.Position:= 0; <=====Failing here with an access violation
>        fMem.Read(cmd, 4);
>    finally
>      fMem.Destroy;
>  end;
>

I believe you are still trying to overwrite the fMem object with the Buf
data, corrupting your fMem stream.
This is why you get the AV at that line as the previous line you are
screwing up the fMem object.

cheers,
Paul.

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive