FAQ
do any of you know of a good site that has examples on when and how to use
the udp functions such as ResolveUDP, DialUDP, etc.? i've been reading the
golang.org/pkg pages and i don't quite understand how to use them.

Thanks!
On Friday, November 27, 2009 8:28:12 PM UTC-5, ish wrote:

The following server code has a problem. The write by server to
connection always fails.
I have not been able to find the solution.
--
package main

import (
"fmt";
"net";
"os";
"strings";
)

func main() {
var buf [1000]byte;
sout := "The answer";
bout := strings.Bytes(sout);

laddr, err := net.ResolveUDPAddr("127.0.0.1:6854");
if err != nil { fmt.Println("Resolv.."); os.Exit(1); }

c, erl := net.ListenUDP("udp", laddr);
if erl != nil { fmt.Println("Listen.."); os.Exit(1); }

n, erd := c.Read(buf[0:128]);
if erd != nil { fmt.Println("Read.."); os.Exit(1); }
fmt.Println("Read: ", n);
fmt.Println("Writing: ", len(bout));
_, erw := c.Write(bout); //fails
if erw != nil { fmt.Println("Write.."); os.Exit(1); }

fmt.Print("Main stops\n");
}
--
-ish
--

Search Discussions

  • Sonia Hamilton at Sep 18, 2012 at 5:23 am
    There's an example in a library I'm using at the moment, for doing SNMP
    calls - https://github.com/soniah/gosnmp/blob/dev/gosnmp.go

    Whether or not it's a _good_ example is debatable :)

    Sonia
    On Saturday, 28 November 2009 12:28:12 UTC+11, ish wrote:

    The following server code has a problem. The write by server to
    connection always fails.
    I have not been able to find the solution.
    --
    package main

    import (
    "fmt";
    "net";
    "os";
    "strings";
    )

    func main() {
    var buf [1000]byte;
    sout := "The answer";
    bout := strings.Bytes(sout);

    laddr, err := net.ResolveUDPAddr("127.0.0.1:6854");
    if err != nil { fmt.Println("Resolv.."); os.Exit(1); }

    c, erl := net.ListenUDP("udp", laddr);
    if erl != nil { fmt.Println("Listen.."); os.Exit(1); }

    n, erd := c.Read(buf[0:128]);
    if erd != nil { fmt.Println("Read.."); os.Exit(1); }
    fmt.Println("Read: ", n);
    fmt.Println("Writing: ", len(bout));
    _, erw := c.Write(bout); //fails
    if erw != nil { fmt.Println("Write.."); os.Exit(1); }

    fmt.Print("Main stops\n");
    }
    --
    -ish
    --
  • Jim Teeuwen at Sep 18, 2012 at 4:12 pm
    This may be of some help: http://jan.newmarch.name/go/

    On Tuesday, September 18, 2012 5:51:07 AM UTC+2, melissa...@gmail.com wrote:

    do any of you know of a good site that has examples on when and how to use
    the udp functions such as ResolveUDP, DialUDP, etc.? i've been reading the
    golang.org/pkg pages and i don't quite understand how to use them.

    Thanks!
    On Friday, November 27, 2009 8:28:12 PM UTC-5, ish wrote:

    The following server code has a problem. The write by server to
    connection always fails.
    I have not been able to find the solution.
    --
    package main

    import (
    "fmt";
    "net";
    "os";
    "strings";
    )

    func main() {
    var buf [1000]byte;
    sout := "The answer";
    bout := strings.Bytes(sout);

    laddr, err := net.ResolveUDPAddr("127.0.0.1:6854");
    if err != nil { fmt.Println("Resolv.."); os.Exit(1); }

    c, erl := net.ListenUDP("udp", laddr);
    if erl != nil { fmt.Println("Listen.."); os.Exit(1); }

    n, erd := c.Read(buf[0:128]);
    if erd != nil { fmt.Println("Read.."); os.Exit(1); }
    fmt.Println("Read: ", n);
    fmt.Println("Writing: ", len(bout));
    _, erw := c.Write(bout); //fails
    if erw != nil { fmt.Println("Write.."); os.Exit(1); }

    fmt.Print("Main stops\n");
    }
    --
    -ish
    --
  • Melissa Alleyne at Sep 19, 2012 at 3:18 am
    this is amazing! thanks!
    On Tuesday, September 18, 2012 11:04:29 AM UTC-4, Jim Teeuwen wrote:

    This may be of some help: http://jan.newmarch.name/go/


    On Tuesday, September 18, 2012 5:51:07 AM UTC+2, melissa...@gmail.comwrote:
    do any of you know of a good site that has examples on when and how to
    use the udp functions such as ResolveUDP, DialUDP, etc.? i've been reading
    the golang.org/pkg pages and i don't quite understand how to use them.

    Thanks!
    On Friday, November 27, 2009 8:28:12 PM UTC-5, ish wrote:

    The following server code has a problem. The write by server to
    connection always fails.
    I have not been able to find the solution.
    --
    package main

    import (
    "fmt";
    "net";
    "os";
    "strings";
    )

    func main() {
    var buf [1000]byte;
    sout := "The answer";
    bout := strings.Bytes(sout);

    laddr, err := net.ResolveUDPAddr("127.0.0.1:6854");
    if err != nil { fmt.Println("Resolv.."); os.Exit(1); }

    c, erl := net.ListenUDP("udp", laddr);
    if erl != nil { fmt.Println("Listen.."); os.Exit(1); }

    n, erd := c.Read(buf[0:128]);
    if erd != nil { fmt.Println("Read.."); os.Exit(1); }
    fmt.Println("Read: ", n);
    fmt.Println("Writing: ", len(bout));
    _, erw := c.Write(bout); //fails
    if erw != nil { fmt.Println("Write.."); os.Exit(1); }

    fmt.Print("Main stops\n");
    }
    --
    -ish
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 18, '12 at 4:33a
activeSep 19, '12 at 3:18a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase