 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Muzzy Guest
|
Posted: Tue Dec 16, 2003 10:20 pm Post subject: TcpClient.ReadBuffer fires 'Out of memory' for no reason |
|
|
Hi again,
I have a problem i can't explain: tcp server sends a StringStream with
size 42,345 bytes
When itry to read the stream from client, i get following:
Var
CStream : TStringStream;
....
CStream := TStringStream.Create('');
....
1. TcpClient.ReadStream(CStream); - fires 'Out of memory' exception
2. But if: TcpClient.ReadStream(CStream, 43000) - it freezes, probably
waiting for additional data from server..
So, why 'Out of service' if it's only 40Kb of data?
Or i make some wrong assumptions?
Thank you,
Andrey
|
|
| Back to top |
|
 |
Muzzy Guest
|
Posted: Tue Dec 16, 2003 10:26 pm Post subject: Re: TcpClient.ReadBuffer fires 'Out of memory' for no re |
|
|
Muzzy wrote:
| Quote: | Hi again,
I have a problem i can't explain: tcp server sends a StringStream with
size 42,345 bytes
When itry to read the stream from client, i get following:
Var
CStream : TStringStream;
...
CStream := TStringStream.Create('');
...
1. TcpClient.ReadStream(CStream); - fires 'Out of memory' exception
2. But if: TcpClient.ReadStream(CStream, 43000) - it freezes, probably
waiting for additional data from server..
So, why 'Out of service' if it's only 40Kb of data?
Or i make some wrong assumptions?
|
And also it doesn't fire OnWorkBegin if i don't specify buffer size...
Andrey
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Dec 17, 2003 4:13 am Post subject: Re: TcpClient.ReadBuffer fires 'Out of memory' for no re |
|
|
"Muzzy" <leyandrew (AT) yahoo (DOT) com> wrote
| Quote: | 1. TcpClient.ReadStream(CStream); - fires 'Out of memory' exception
|
Is that your EXACT code? If so, then you are not specifying the AByteCount
or AReadUntilDisconnect parameters at all. As such, they will have default
values, which will tell ReadStream() to expect the first 4 bytes of the
stream data to be the length of the remaining data. If the sender of the
data is not actually specying the data length in the first 4 bytes, then
ReadStream() is going to end up incorrectly interpreting random bytes as
being a size, which could very well cause ReadStream to try to allocate an
outrageously large amount of memory.
Who exactly are you reading the stream data from in the first place? Is it
a program you wrote yourself as well? If so, what does the code look like
that is sending the data? If you did not write the sending program
yourself, then what exactly is it doing? You are probably implementing its
protocols wrong.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Dec 17, 2003 4:14 am Post subject: Re: TcpClient.ReadBuffer fires 'Out of memory' for no re |
|
|
"Muzzy" <leyandrew (AT) yahoo (DOT) com> wrote
| Quote: | And also it doesn't fire OnWorkBegin if i don't specify buffer size...
|
Because the exception occured before it had a chance to do so.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|