I was reading the type declaration for http.Server
in the documentation and I came across this.
type Server struct {
Addr string // TCP address to listen on, ":http" if empty
// more...
}
If you call srv.ListenAndServe()
and srv.Addr
is an empty string, then ListenAndServe
will pass ":http"
to net.Listen
(http/server.go).
What does ":http"
mean?
Most browsers make HTTP requests on ports 80 and 443 by default. Typically, the default configuration option is for servers to listen on all IP addresses on port 80.
On a Web server or Hypertext Transfer Protocol daemon, port 80 is the port that the server "listens to" or expects to receive from a Web client, assuming that the default was taken when the server was configured or set up. A port can be specified in the range from 0-65536 on the NCSA server.
You cannot use the same port for both http and https. Unlike some other types of servers, webservers do not negotiate encryption. If it's encrypted (https), it must be sent to 443/8443. If it's plain text (http) it must be sent to 80/8080.
Sometimes ports have aliases. http
is 80.You can see more names here: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With