How to declare ports in Cloud9 using Python

谁说我不能喝 提交于 2019-12-03 14:38:43

process.env.PORT and process.env.IP from Node.js sound like os.environ["PORT"] and os.environ["IP"] in Python. Perhaps you can try:

reactor.listenTCP(int(os.environ["PORT"]), site, interface=os.environ["IP"])

Probably this is limitation of c9 environment management, so users dont abuse their service too much. I would assume that they have some level of management for Node.js used resources and thus allow these to open ports.

If this was the case and I had to work with cloud9, I would probably approach this as follows: - create Node.js service which would act as a proxy, listening on twisted behalf - create new reactor with overriden listenTCP and listenUDP methods, which would bind these to Node.js proxy service.

The way how proxy would work is as follows, Node.js would initially listen on one "management" TCP port. Then, when twisted service starts up, it would create a TCP connection between Node.js and itself through that port. Then, whenever listenTCP or listenUDP is called, these commands would then be dispatched to Node.js service, which in return would open the port and all of the comunication through that port would then be proxied to twisted through that existing TCP connection.

It's worth mentioning that Jean-Paul's answer worked for me as well, but I had to use 'address' instead of 'interface':

http_server.listen(int(os.environ.get("PORT")), address=os.environ["IP"])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!