FAQ
Hi there,

I'm creating a TCP connection in Windows (I've tested it in Win7x64 and
Win8.1x64 and I get the same result) to read the request sent from IIS 7. I
set a deadline to the connection and then read the data sent from IIS.
Here's a simplification of the real code

ln, err := net.Listen("tcp", ":8080")
if err != nil {
     log.Fatal(err)
}

conn, err := ln.Accept()
conn.SetDeadline(time.Now().Add(10 * time.Second))

buf = make([]byte, 1024)

for {
     n, err = conn.Read(buf)
     .
     .
     .
}

Let say that the amount of data sent from ISS is 1400 bytes so I've
realized that the last read never returns because the amount of bytes
returned is less than 1024.

I expected to get the bytes remaining (376) but the Read() never return.

Can somebody explain me why is this happening?

Thanks.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Konstantin Khomoutov at Nov 19, 2014 at 5:54 pm

    On Wed, 19 Nov 2014 09:36:18 -0800 (PST) Roberto García López wrote:

    Hi there,

    I'm creating a TCP connection in Windows (I've tested it in Win7x64
    and Win8.1x64 and I get the same result) to read the request sent
    from IIS 7. I set a deadline to the connection and then read the data
    sent from IIS. Here's a simplification of the real code

    ln, err := net.Listen("tcp", ":8080")
    if err != nil {
    log.Fatal(err)
    }

    conn, err := ln.Accept()
    conn.SetDeadline(time.Now().Add(10 * time.Second))

    buf = make([]byte, 1024)

    for {
    n, err = conn.Read(buf)
    .
    .
    .
    }

    Let say that the amount of data sent from ISS is 1400 bytes so I've
    realized that the last read never returns because the amount of bytes
    returned is less than 1024.
    No, conn.Read() would read *up to* the length of the slice you've
    supplied it, but the amount of data it reads before returning can be
    in range [1, len (buffer)]. See [1] for a recent discussion.

    So there might be multiple reasons for Read() to not return: IIS not
    sending those bytes (unlikely), IIS sending those bytes but not tearing
    down the connection to they wait somewhere in the network stack.
    Or that may be you somehow mishandling the data.
    I expected to get the bytes remaining (376) but the Read() never
    return.
    Did you verify (using good old fmt.Printf() for instance) that `n`
    is exactly what you think it is on each iteration?
    Did you look at what IIS sends using Wireshark or Microsoft Network
    Monitor or a similar tool and verify it realy sends the "missing" data?

    1. http://stackoverflow.com/a/27003111/720999

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 19, '14 at 5:36p
activeNov 19, '14 at 5:54p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase