On Thursday, November 15, 2012 8:09:41 AM UTC-5, Ethan Burns wrote:
> This for loop does one read, then loops as long as err == nil; it never
> reads again.
> for _, err := conn.Read(buf); err == nil; {
> fmt.Println("Read:", buf)
> }
> You probably wanted this:
> for _, err := conn.Read(buf); err == nil; _, err := conn.Read(buf){
> fmt.Println("Read:", buf)
> }
> See this thread for a bit more info:
> https://groups.google.com/d/topic/golang-nuts/QfKNn6ljc5Q/discussion
> Best,
> Ethan
> On Thursday, November 15, 2012 2:10:43 AM UTC-5, Hunter F wrote:
>> I've been having trouble wrapping my head around around a
>> problem I've been having with the standard net package.
>> I want to read n bytes at a time of a socket. In this case 10 bytes of a
>> socket to google's webserver.
>> Full code: http://play.golang.org/p/zAQsO1x9rW
>> Running that I get:
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> Read: [72 84 84 80 47 49 46 48 32 50]
>>> ...
>> Continuing on forever.
>> It appears buf is not changing for each iteration of the loop. The first
>> 10 bytes of the server's response stays in the slice through each iteration
>> of the loop.
>> I've tried using bufio package to wrap it but the problem remains the
>> same.