端口6000有什么特别之处? [英] What's special about port 6000?

查看:1775
本文介绍了端口6000有什么特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动Mac.从 quickstart页面中获取基本的Flask应用,并将端口更改为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)

将其保存在名为的文件中test.py.然后创建一个virtualenv,运行pip install flask,然后调用test.py.这是您将在终端上看到的内容:

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

因此Flask声称已绑定到端口6000.现在启动浏览器并导航到localhost:6000.我原本希望看到愚蠢的消息Hello World,当我将port参数留给run并导航到localhost:5000时,就是这种情况.但是,这是我看到的:

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:

现在在终端上执行Ctrl-C,并停止正在运行的进程.将端口更改为6001,重新运行命令. Hello World又回来了!怎么会这样?没有其他进程连接到端口6000. lsof -i | grep 6000返回0个结果,并且如果有任何进程,则Flask首先将无法绑定到该端口.防火墙已关闭.

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.

有什么想法吗?

推荐答案

好的,找到了答案.浏览器会阻止某些端口,尽管它们不在系统端口范围内,但其中一些处于广泛用于本地Web开发的范围内. 此答案中的链接指向浏览器供应商和详尽列表的依据.正如德国人所说,维德是胶凝体".

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".

感谢@glyphobet的评论,导致了正确的答案.

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

这篇关于端口6000有什么特别之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆