# Back-to-basics - Source port in TCP connection

When making a TCP request, you need to specify the IP and the port. The combination is a socket. Some port is quite famous, such as 80 for web, 22 for ssh,… But have you ever wonder about the number of port from your end?

## The experiment

The idea is coming from javax.servlet.ServletRequest, I saw the method getRemotePort which will Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.. That makes me wonder which port will be used when fire a TCP connections.

I make a simple program, it will prints out the source port of a connection.

Open http://localhost:8080/display-local-port/ by the browser, the pod is a big value, and sometimes changed (54220 or something).

## The investigation

It turns out the port is assigned by the OS, it calls Ephemeral port.

You can specify the port from origin also, for example with curl by using --local-port option.

## What to go from here

It leads to a new question, how many connection a server can handle. As in Linux it is a specific number (Many Linux kernels use the port range 32768 to 61000), so is it limited by opening ports left?

It turns out more complicated, as discussions in here

Still questioning myself, will update if I found the answer.