<p dir="auto">According to the package <a href="https://golang.org/pkg/net/#Dial" rel="nofollow">doc</a>, address without host specified should be allowed, e.g. <code class="notranslate">Dial("tcp", ":80")</code>. But an error <code class="notranslate">connectex: The requested address is not valid in its context</code> is returned on windows 10.</p>
<p dir="auto">Please answer these questions before submitting your issue. Thanks!</p>
<ol dir="auto">
<li>What version of Go are you using (<code class="notranslate">go version</code>)?</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ go version
go version go1.6 windows/amd64"><pre class="notranslate"><code class="notranslate">$ go version
go version go1.6 windows/amd64
</code></pre></div>
<ol dir="auto">
<li>What operating system and processor architecture are you using (<code class="notranslate">go env</code>)?</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:/Users/taylorchu/go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1"><pre class="notranslate"><code class="notranslate">$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:/Users/taylorchu/go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
</code></pre></div>
<ol dir="auto">
<li>
<p dir="auto">What did you do?</p>
<p dir="auto"><a href="http://play.golang.org/p/G8gttmZyvA" rel="nofollow">http://play.golang.org/p/G8gttmZyvA</a></p>
</li>
<li>
<p dir="auto">What did you expect to see?</p>
</li>
</ol>
<p dir="auto">net.Dial without specifying host should cause no error.</p>
<ol dir="auto">
<li>What did you see instead?</li>
</ol>
<p dir="auto"><code class="notranslate">connectex: The requested address is not valid in its context.</code></p>
<pre class="notranslate">What steps will reproduce the problem?

run this program on windows

package main

import (
    "log"
    "net"
)

func dial() error {
    l, err := net.Listen("tcp", ":0")
    if err != nil {
        return err
    }

    go func() {
        c, err := l.Accept()
        if err != nil {
            return
        }
        c.Close()
    }()

    c, err := net.Dial("tcp", l.Addr().String())
    if err != nil {
        return err
    }
    c.Close()
    return nil
}

func main() {
    err := dial()
    if err != nil {
        log.Fatal(err)
    }
}


What is the expected output?

Should output noting.

What do you see instead?

2013/08/30 16:43:22 dial tcp 0.0.0.0:1406: ConnectEx tcp: The format of the specified
network name is invalid.

Please use labels and text to provide additional information.

The problem seems to be that l.Addr().String() returns '0.0.0.0', but connecting to that
address is not allowed on windows. From
<a href="http://msdn.microsoft.com/en-us/library/aa923167.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa923167.aspx</a>

" ... If the address member of the structure specified by the name parameter is
all zeroes, connect will return the error WSAEADDRNOTAVAIL. ..."</pre>