On a Mac, port 5000 is taken before your project starts. macOS runs AirPlay Receiver, which lets an iPhone or another Mac stream to this one, and its process, ControlCenter, listens on TCP 5000 and 7000. Apple’s own port list names both ports as AirPlay. The Flask documentation puts it plainly: “macOS Monterey and later automatically starts a service that uses port 5000.”

Commands tested on macOS 27.0.1 on 2026-10-20. Addresses and names in the output are replaced.

The symptom: “address already in use” or a 403 from AirTunes

You see one of two things.

Your server will not start. A Python server on port 5000 stops with:

python3 -m http.server 5000
OSError: [Errno 48] Address already in use

Node says the same in its own words:

Error: listen EADDRINUSE: address already in use :::5000

flask run uses the development server from Werkzeug, which prints a hint that names the cause. This is the text in its source code:

Port 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.
On macOS, try searching for and disabling 'AirPlay Receiver' in System Settings.

Or something answers that is not your app. Open http://localhost:5000/ and you get a 403 Forbidden with an empty body. The headers show who answered:

curl -sI http://localhost:5000/
HTTP/1.1 403 Forbidden
Content-Length: 0
Server: AirTunes/980.77.5
X-Apple-ProcessingTime: 0
X-Apple-RequestReceivedTimestamp: 484179429

Server: AirTunes is the AirPlay receiver. Your own server never got the request.

Confirm what is using port 5000

  1. Open Terminal (Applications › Utilities).
  2. Ask lsof which process listens on the port. +c 0 prints the full process name:
lsof +c 0 -nP -iTCP:5000 -sTCP:LISTEN
COMMAND       PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCenter 661 user   11u  IPv4 0xf995c465003c0f25      0t0  TCP *:5000 (LISTEN)
ControlCenter 661 user   12u  IPv6 0x508bce2741500fd1      0t0  TCP *:5000 (LISTEN)

Without +c 0, lsof cuts the name to nine characters and prints ControlCe. That is the same process. *:5000 means it listens on every network interface, over IPv4 and IPv6.

ControlCenter runs as your user, so sudo is not needed here. If the command prints nothing, the port is free, or a process of another user holds it; sudo lsof -nP -iTCP:5000 -sTCP:LISTEN lists those too.

Why netstat says “commplex-main”

Without -n (netstat) or -P (lsof), the tools print the service name from /etc/services instead of the number:

netstat -a -p tcp | grep commplex
tcp6       0      0  *.commplex-main        *.*                    LISTEN
tcp4       0      0  *.commplex-main        *.*                    LISTEN

commplex-main is the name /etc/services gives port 5000, a label from the IANA port list. It has nothing to do with AirPlay. To see the process in netstat, add -v:

netstat -anv -p tcp | grep '\.5000 '

Each line includes ControlCenter:661, the process name and its PID.

Fix 1: turn off AirPlay Receiver

If you do not stream to this Mac from an iPhone, iPad or another Mac, turn the receiver off. On macOS 27:

  1. Choose Apple menu › System Settings.
  2. Click General in the sidebar.
  3. Click AirDrop & Continuity.
  4. Turn off AirPlay Receiver.
  5. Run lsof +c 0 -nP -iTCP:5000 -sTCP:LISTEN again. No output means the port is free.

The setting has moved between macOS versions. Apple’s Mac User Guide for each version puts it here:

macOS Where AirPlay Receiver is
27 System Settings › General › AirDrop & Continuity
Tahoe 26 System Settings › General › AirDrop & Continuity
Ventura 13, Sonoma 14, Sequoia 15 System Settings › General › AirDrop & Handoff
Monterey 12 System Preferences › Sharing › AirPlay Receiver checkbox

If you cannot find the switch, search for “AirPlay Receiver” in System Settings. Apple notes that on a Mac enrolled in mobile device management (MDM), “AirPlay Receiver may be unavailable”, so a work Mac may not let you turn it off.

Can you change the AirPlay Receiver port?

No. Apple’s guide lists three settings for the receiver: on or off, who may stream (“Allow AirPlay for”) and a password. There is no port number to change. Your choice is to turn the receiver off or to move your own server.

Fix 2: move your server to another port

If you use AirPlay to this Mac, leave it on and give your project another port. 5050 is used below; any free port works.

Server Command
Flask flask run --port 5050
Python’s built-in server python3 -m http.server 5050
A Docker container that listens on 5000 inside docker run -p 5050:5000 <image>

Flask’s documentation gives the same advice: “use flask run --port 5001 to pick a different port.” In Docker, -p 5050:5000 maps port 5050 on the host (your Mac) to port 5000 in the container, so the container itself needs no change.

Check that the new port answers:

curl -sI http://localhost:5050/ | head -2
HTTP/1.0 200 OK
Server: SimpleHTTP Python/3.15.0

The 127.0.0.1 trap

Some servers do start on 5000 if you bind them to 127.0.0.1 only. On the test Mac a Node server on 127.0.0.1:5000 started without an error, next to ControlCenter:

COMMAND         PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCenter   661 user   11u  IPv4 0xf995c465003c0f25      0t0  TCP *:5000 (LISTEN)
ControlCenter   661 user   12u  IPv6 0x508bce2741500fd1      0t0  TCP *:5000 (LISTEN)
node          85833 user   15u  IPv4  0xccd121e3b17d8d0      0t0  TCP 127.0.0.1:5000 (LISTEN)

It looks fixed, but it is not:

Request Who answered
curl -sI http://127.0.0.1:5000/ HTTP/1.1 200 OK, the Node server
curl -sI http://localhost:5000/ HTTP/1.1 403 Forbidden, Server: AirTunes/980.77.5

localhost also means the IPv6 address ::1, and curl tried that first (Trying [::1]:5000...). Only AirPlay listens on IPv6 port 5000, so it got the request. Sharing a port with AirPlay works for one address and fails for the other. Use a different port.

Why killing ControlCenter does not free the port

The usual “kill port” one-liner finds PID 661 and kills it. For ControlCenter that is the wrong fix, because launchd, the macOS service manager, is set to start it again.

ControlCenter is a launch agent. Its definition, /System/Library/LaunchAgents/com.apple.controlcenter.plist, has these keys:

plutil -p /System/Library/LaunchAgents/com.apple.controlcenter.plist
  "KeepAlive" => {
    "SuccessfulExit" => false
  }
  ...
  "Program" => "/System/Library/CoreServices/ControlCenter.app/Contents/MacOS/ControlCenter"
  "ThrottleInterval" => 1

The launchd.plist manual explains SuccessfulExit set to false: “the job will be restarted” when the program does not exit cleanly. ThrottleInterval of 1 cuts the minimum time between launches from the default 10 seconds to 1 second. While AirPlay Receiver is on, the new ControlCenter takes port 5000 back.

To keep the port free, turn off AirPlay Receiver. The process stays; the port closes.

Is port 5000 safe?

An open port is as safe as the service behind it and the people who can reach it. AirPlay Receiver listens on every interface, so other devices on your network can connect to it. On the test Mac, whose firewall was off, a connection to the Mac’s own network address went through:

nc -zv -G 2 192.168.1.23 5000
Connection to 192.168.1.23 port 5000 [tcp/commplex-main] succeeded!

What another device can do there depends on the “Allow AirPlay for” setting, in the same pane as the switch:

Allow AirPlay for Who can stream to this Mac
Current User Only devices “where you’re signed in to the same Apple Account”
Anyone on the Same Network Any nearby Mac, iPhone or iPad on the same network
Everyone Any Mac, iPhone or iPad

Apple also lets you require a password for AirPlay to this Mac. If you keep the receiver, Current User plus a password limits who can stream. This limits who may use AirPlay; the port itself stays open. If you never stream to this Mac, turning the receiver off is simpler, and the port closes.

Check port 5000 from another Mac

lsof shows what listens. To see what the network sees, test the Mac from a second Mac on the same network. In Terminal on the second Mac, replace the address with the first Mac’s own (run ipconfig getifaddr en0 on it):

nc -zv -G 2 192.168.1.23 5000
curl -sI http://192.168.1.23:5000/ | grep -i '^server'

With AirPlay Receiver on, nc reports succeeded and curl prints Server: AirTunes/980.77.5. After you turn it off, nc should report Connection refused.

Port Scan in Netutilus does the same check without Terminal, and it is free:

  1. Open Netutilus and choose Port Scan under Network Tools in the sidebar.
  2. Enter the Mac’s address, and 5000,7000 in the ports field.
  3. Turn on Detect services.
  4. Click Start Scan.

With the receiver on, both ports show Open, and Detect services reads the server’s name into the Software column. Netutilus asks a web port for its headers, so port 5000 should show AirTunes with its version.

To confirm the fix, use Path Check, also free: enter the address and port 5000, then click Start Trace. Refused means the Mac answered and nothing listens on that port any more. If every port to a device at home times out, Netutilus may need Local Network access, in System Settings › Privacy & Security › Local Network.

The ports explainer covers open, closed and filtered, and how to check open ports on a Mac lists everything else your Mac listens on.

Port 7000 is AirPlay too

The same ControlCenter process listens on TCP 7000, which Apple’s list also names as AirPlay. It answers the same way:

curl -sI http://127.0.0.1:7000/ | grep -i '^server'
Server: AirTunes/980.77.5

nc calls it afs3-fileserver, the name /etc/services gives port 7000. A server that wants 7000 hits the same conflict, and the same two fixes apply.