[Pharo-project] reading *exactly* n bytes from socket

Schwab,Wilhelm K bschwab at anest.ufl.edu
Sun Jan 15 14:10:24 EST 2012


I wouldn't forget it too soon.  Streams should work as advertised or raise an error.  My (compromise) proposal remains as follows:



From: pharo-project-bounces at lists.gforge.inria.fr [pharo-project-bounces at lists.gforge.inria.fr] on behalf of Max Leske [maxleske at gmail.com]
Sent: Sunday, January 15, 2012 6:18 AM
To: pharo-project at lists.gforge.inria.fr
Subject: Re: [Pharo-project] reading *exactly* n bytes from socket

Sorry, forget what I just wrote…
I found the bug in my code. Should have checked if the connection is still open :-/


On 15.01.2012, at 12:09, Max Leske wrote:

> Hey guys
> I'm having a problem with Socket / SocketStream. When I know that the next packet of data from the server is going to be 10'000 bytes I want to ask the socket for exactly 10'000 bytes of data (I don't care how long it takes). However, the comments in the Socket class suggest that the buffer might not be filled entirely when the message answers. As a consequence, my code fails because the ByteArray sometimes has a number of zero bytes at the end which obviously wasn't expected.
> I also tried to use SocketStream to get around this problem but wasn't successful. Am I supposed to handle this case myself or did I overlook something?
> Cheers,
> Max

More information about the Pharo-dev mailing list