More apps from usSnipora

Guide

Port 5000 in use on Mac? It’s AirPlay Receiver

Your Flask app says port 5000 is in use, or localhost:5000 answers with 403 Forbidden, but you never started anything there. On a Mac, that’s almost always AirPlay Receiver.

By Anmol Sethi · Updated

In short

Since macOS Monterey, AirPlay Receiver (the ControlCenter process) listens on ports 5000 and 7000. Turn it off in System Settings → General → AirDrop & Handoff → AirPlay Receiver, or run your app on another port such as 5001. Killing the process doesn’t help: macOS starts it again.

The symptoms

  • Flask: Address already in use. Port 5000 is in use by another program. Recent versions add a hint about AirPlay Receiver.
  • Docker: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use
  • ASP.NET, a local Docker registry (registry:2) or anything else that defaults to 5000 fails the same way.
  • Opening http://localhost:5000 shows 403 Forbidden and an empty page, even with your server stopped.

Rather click than type? Portlivo shows every port with its project and frees it in one click. Try it free for 7 days →

Confirm it’s AirPlay

lsof -nP -iTCP:5000 -sTCP:LISTEN
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
ControlCe 423 you    9u  IPv4  0x2f88…      0t0  TCP *:5000 (LISTEN)
ControlCe 423 you   10u  IPv6  0x7a41…      0t0  TCP *:5000 (LISTEN)

ControlCe is ControlCenter, cut to nine characters. To be sure it’s the AirPlay server and not something else, look at the Server header:

curl -sI http://localhost:5000 | grep -i server
Server: AirTunes/…

AirTunes is the AirPlay receiver. If you see another name instead, it’s a real leftover process: follow Port already in use on a Mac.

Fix 1: turn off AirPlay Receiver

  1. Open System Settings → General → AirDrop & Handoff.
  2. Switch off AirPlay Receiver.
  3. Run lsof -nP -iTCP:5000 -sTCP:LISTEN again: it prints nothing, and port 5000 is yours.

This frees 7000 too. You lose the ability to AirPlay from an iPhone or another Mac to this Mac; streaming from this Mac to a TV or speaker still works. Switch it back on whenever you need it.

Don’t kill ControlCenter. It also draws the menu bar’s Control Center, and macOS restarts it within seconds, AirPlay listener included.

Fix 2: use another port

If you use AirPlay Receiver, leave it on and move your app. 5001 is the usual choice:

flask run --port 5001
python app.py                       # with app.run(port=5001)
docker run -p 5001:5000 my-image     # host 5001 → container 5000
dotnet run --urls http://localhost:5001

With Docker, only the left side of -p changes: the app inside the container keeps listening on 5000. In Compose that’s ports: ["5001:5000"]. For a team that mixes Macs and other machines, make the port an environment variable, for example FLASK_RUN_PORT=5001 in .flaskenv.

Port 7000

AirPlay Receiver holds 7000 as well, which bites Cassandra (inter-node traffic), some Django and Node setups, and anything that picked 7000 to stay clear of 5000. The fixes are the same: turn the receiver off, or move to 7001 or above.

The one-click way: Portlivo

With Show system processes on, Portlivo lists ControlCenter on 5000 and 7000 next to your dev servers, so a taken port has a name before you start anything. When a server you started from Portlivo can’t bind its port, the notification says what holds it.

Questions people ask

What is using port 5000 on my Mac?
Usually AirPlay Receiver, run by the ControlCenter process. lsof -nP -iTCP:5000 -sTCP:LISTEN shows it as ControlCe.
How do I free port 5000 on macOS?
Turn off System Settings → General → AirDrop & Handoff → AirPlay Receiver. Killing the process doesn’t work: macOS starts it again.
Why does localhost:5000 return 403 Forbidden?
Your app isn’t running there; AirPlay Receiver is, and it refuses browser requests. curl -sI http://localhost:5000 shows Server: AirTunes.
Does turning off AirPlay Receiver stop me AirPlaying to my TV?
No. It only stops other devices from AirPlaying to this Mac.

Try Portlivo free for 7 days. Every feature, no account.

Download for Mac

Still have a question?

Write to us — a real developer reads every email and replies personally.

support@portlivo.com