FAQ
I'm a go newbie. Thanks for this great lang.

I've had a UDP connecting listen on ADDR, what's the best practice of get
the data from the client, especially when I don't even know the approximate
data length( can't fit in buffer )?

I have some codes like this:

     //buinding connections ...

     data := bytes.NewBuffer(nil)
     var buf [512]byte
     for {
         fmt.Println("_")
         _, _, err := l.ReadFromUDP(buf[0:])
         if err != nil {
             if err == io.EOF {
                 break
             }
             os.Exit(1)
         }
         fmt.Println("/")
         data.Write(buf[0:])
         fmt.Println(string(data.Bytes()))
         fmt.Println("|")
     }

     fmt.Println(string(data.Bytes()))

     os.Exit(0)


I can only get the first 512 bytes in the codes above.

How could I handle the data receiving if the data is very huge, I mean, 16G
for example.

How can I use the buffer to receive len(buffer) data and then again and
again?

Thank you.








--
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/groups/opt_out.

Search Discussions

  • Benjamin Measures at Aug 11, 2013 at 1:38 pm

    On Saturday, 10 August 2013 11:24:48 UTC+1, DennisYuan wrote:

    what's the best practice of get the data from the client, especially when
    I don't even know the approximate data length( can't fit in buffer )?
    Generally in Go, you can stream things via Readers/Writers.

    Check out the Listener example in the
    docs: http://golang.org/pkg/net/#example_Listener . This just echos back by
    io.Copy(c, c) but could easily be modified to copy to any other Writer
    (interface), such as a file on disk, for example.

    Hth.

    --
    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/groups/opt_out.
  • Юрий Соколов at Aug 11, 2013 at 6:54 pm
    UDP is a unreliable, unordered, packet oriented protocol. Size of single
    packed is limited, and one could count only on 512 guaranteed bytes
    (although, some networks could pass larger packets).
    So that, there is no such thing as HUGE DATA with UDP - you could only have
    MANY SMALL UNORDERED PACKETS.

    суббота, 10 августа 2013 г., 14:24:48 UTC+4 пользователь DennisYuan написал:
    I'm a go newbie. Thanks for this great lang.

    I've had a UDP connecting listen on ADDR, what's the best practice of get
    the data from the client, especially when I don't even know the approximate
    data length( can't fit in buffer )?

    I have some codes like this:

    //buinding connections ...

    data := bytes.NewBuffer(nil)
    var buf [512]byte
    for {
    fmt.Println("_")
    _, _, err := l.ReadFromUDP(buf[0:])
    if err != nil {
    if err == io.EOF {
    break
    }
    os.Exit(1)
    }
    fmt.Println("/")
    data.Write(buf[0:])
    fmt.Println(string(data.Bytes()))
    fmt.Println("|")
    }

    fmt.Println(string(data.Bytes()))

    os.Exit(0)


    I can only get the first 512 bytes in the codes above.

    How could I handle the data receiving if the data is very huge, I mean,
    16G for example.

    How can I use the buffer to receive len(buffer) data and then again and
    again?

    Thank you.







    --
    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/groups/opt_out.
  • Kyrieuon at Aug 12, 2013 at 4:03 am

    On Saturday, August 10, 2013 12:24:48 PM UTC+2, DennisYuan wrote:
    I can only get the first 512 bytes in the codes above.

    How could I handle the data receiving if the data is very huge, I mean,
    16G for example.

    How can I use the buffer to receive len(buffer) data and then again and
    again?
    I recently ran into the same problem. An UPD datagram can carry up to 64
    KiB of data, or even more with IPv6.

    It seems that the Go API does not provide a mechanism to efficiently handle
    UPD datagrams of arbitrary size.

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 11, '13 at 1:23a
activeAug 12, '13 at 4:03a
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase