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

Updated · 2 min read

Since macOS Monterey, the AirPlay Receiver listens on ports 5000 and 7000. Flask uses 5000 by default, so flask run stops with Address already in use. Turn the receiver off, or run your server on another port:

bash
flask run --port 5001

Check that it's AirPlay

bash
lsof -nP -iTCP:5000 -sTCP:LISTEN
text
COMMAND   PID   USER   FD   TYPE  DEVICE  SIZE/OFF NODE NAME
ControlCe 617    you   11u  IPv4  0xd7…        0t0  TCP *:5000 (LISTEN)
ControlCe 617    you   12u  IPv6  0xc9…        0t0  TCP *:5000 (LISTEN)

ControlCe is ControlCenter, its name cut to nine letters by lsof. It runs under your own user, so kill would work, but don't: it's part of macOS and starts again at once.

Turn off AirPlay Receiver

Open System Settings ▸ General ▸ AirDrop & Handoff and turn off AirPlay Receiver. Ports 5000 and 7000 are free right away. Until you turn it back on, you can't AirPlay from an iPhone or iPad to this Mac.

Or keep AirPlay and move your server

  • Flask: flask run --port 5001, or app.run(port=5001) in your script.
  • Anything that reads PORT: PORT=5001 npm start.
  • Choose a port away from 5000 and 7000 for good, so the clash doesn't come back on the next Mac.

Not sure what holds a port in general? See Port already in use on Mac.

How Portroom handles it

Portroom names what holds a port

When a project’s port is taken, Portroom says by what and offers the next free one with Use N, so a clash with AirPlay is one click, whether or not you know about AirPlay.

With an Auto port, a project starts on the first free port in your range and keeps it while it stays free, so bookmarks keep working.

A project in Portroom whose port is taken, with the next free port offeredA project in Portroom whose port is taken, with the next free port offered

Something wrong or out of date on this page? Write to support@portroom.dev.

More guides

Every dev server on your Mac, in one window.

Free for three servers at once, with 14 days of Pro first. No account.