Re: [go-nuts] Problem with Net UDP (ipv6) client socket

86 views
Skip to first unread message

Jakob Borg

unread,
Aug 2, 2016, 2:25:09 PM8/2/16
to CN47, golang-nuts

On 2 aug. 2016, at 15:19, CN47 <akrc...@gmail.com> wrote:

I'm working on an API that should connect via IPv4 and Ipv6 to a server via UDP packets and send/receive information to/from that server.

Please see the below example. This seems to work even though I've specified "udp" and not "udp6" (Both server and client address are local to a network)

package main

import (
    "fmt"
    "net"
)

func CheckError(err error) {
    if err  != nil {
        fmt.Println("Error: " , err)
    }
}

func main() {
    ServerAddr,err := net.ResolveUDPAddr("udp","[0:0:0:0:0:ffff:c0a8:cd36]:5400")
    CheckError(err)

    LocalAddr, err := net.ResolveUDPAddr("udp", "[0:0:0:0:0:ffff:c0a8:130]:5400")
    CheckError(err)

    Conn, err := net.DialUDP("udp", LocalAddr, ServerAddr)
    CheckError(err)

    defer Conn.Close()
}

However, once I replace those "udp" strings with "udp6" as indicated in the documentation, I get an error from the DialUDP() method "dial udp6 192.168.1.48:5400->192.168.205.54:5400: bind: can't assign requested address".

For what it's worth, the code works if I replace those ipv6 strings with their ipv4 strings and use "udp4" instead of "udp".

Can someone explain why udp6 doesn't seem to work?

Those are IPv4-mapped IPv6 addresses, which is to say regular IPv4 addresses expressed in IPv6 syntax for compatibility purposes. You are using an IPv4 connection, which is why "udp" and "udp4" work but "udp6" doesn't. 

//jb

Jean de Klerk

unread,
May 8, 2017, 4:48:54 PM5/8/17
to golang-nuts, akrc...@gmail.com
Has there been resolution on this? I get this error now and then, too.
Reply all
Reply to author
Forward
0 new messages