为什么无法使用任何端口连接到127.0.0.1上的http服务绑定

I wrote a simple http server in Go language as below:

http.ListenAndServe(":8888", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("hello"))
}))

When I test it on certain machine runs Windows 7, I found client can't connect to the server.

telnet 127.0.0.1 8888
connecting 127.0.0.1… can't open connection to the host.  on port 8888: connect failed. (I translate it from Chinese.)

Then I got the results of other test case:

  1. ping localhost and 127.0.0.1, successful.
  2. telnet localhost 8888, successful.
  3. telnet ::1 8888, successful.
  4. netstat -ano | find "8888", the server has listened 0.0.0.0:8888 and :::8888.
  5. Check the hosts file of OS, it's default configuration (nothing else).
  6. Check the Network Adapter, it doesn't open IPV6 adapter.
  7. The machine is in domain network.
  8. The IP Security Policy is an empty list.
  9. When I opened the MMC(Microsoft Management Console), I got a warning like this:
    message box
    It mean's:
    Can't find resource "$(string.SiteDiscoveryEnableWMI)" (references in property displayName)
. File C:\windows\PolicyDefinitions\inetres.admx, line 64620, row 235

Anyone can tell me what's going on?

If XAMPP is running in your machine, the local server sometimes uses 127.0.0.1 as the default. This could be the reason that ping localhost is working but telnet is not.

Otherwise check other network services or localservers you have running for any conflicts.

Cheers!