Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is port a string and not an integer?

Tags:

http

port

go

People also ask

Is a port an integer?

Physically, a port is a 16-bit integer. Some ports are reserved for particular applications; they are labeled as well-known ports.

Is it a string or an integer?

Integer is a numeric value, while String is a character value represented in quotes.

Is 8080 a valid port number?

The port number 8080 is usually used for web servers, proxy and caching.

Can a port number be 0?

"Port Zero" does not officially exist. It is defined as an invalid port number. But valid Internet packets can be formed and sent "over the wire" to and from "port 0" just as with any other ports.


This is because what appears after the colon can be either a port number or service name.

The following is a valid example where the service name is used instead of a port number:

listener, err := net.Listen("tcp", "localhost:https") // port 443
// ...

The port mapping for a particular service can be looked up using net.LookupPort. On Unix systems, the /etc/services file is sourced for the mappings.