Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's special about port 6000?

Tags:

macos

flask

web

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 http://0.0.0.0:6000/ (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?

like image 731
Ulas Turkmen Avatar asked Mar 27 '15 09:03

Ulas Turkmen


1 Answers

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.

like image 108
Ulas Turkmen Avatar answered Oct 19 '22 00:10

Ulas Turkmen