What's special about port 6000?

Start your Mac. Take the base Flask app from the quickstart page, and change the port to 6000, which gives you the following:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world(): return 'Hello World!'
if __name__ == '__main__': app.debug = True app.run(port=6000)

Save this in a file named e.g. test.py. Then create a virtualenv, run pip install flask, and call test.py. Here is what you will see on the terminal:

 * Running on (Press CTRL+C to quit) * Restarting with stat

So Flask claims to have bound to port 6000. Now start a browser and navigate to localhost:6000. I was expecting to see the silly message Hello World, which is the case when I leave out the port argument to run, and navigate to localhost:5000. But here is what I see instead:

enter image description here

Now do Ctrl-C on the terminal, and stop the running process. Change the port to 6001, rerun the command. Hello World is back! How can this be? There are no other processes connecting to port 6000; lsof -i | grep 6000 returns 0 results, and if there were any processes, Flask would fail to bind to that port in the first place. Firewall is turned off.

Any ideas?

6

1 Answer

OK, found the answer. Browsers block certain ports, although they are not in the system port range, some of them in the ranges widely used for local web development. The links in this answer point to the rationale from the browser vendors and exhaustive lists. As the germans say, "Wieder was gelernt".

Thx to @glyphobet for his comment that led to the right answer.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like