如何在没有Flask的Heroku上托管websocket应用python服务器? [英] How to host websocket app python server on Heroku without Flask?

查看:72
本文介绍了如何在没有Flask的Heroku上托管websocket应用python服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在做一个学校项目,我必须做一个python服务器和android客户端.所以我已经使用python 3使用websockets创建了一个服务器(我没有使用Flask或socket.io等,只是常规的websockets),并在android studio中创建了一个客户端.我一切都在本地运行,效果很好!

So I'm making a school project and I have to make a python server and android client. So I've already created a server using websockets with python 3 (I'm not using Flask or socket.io and etc, just regular websockets) and a client in android studio. I ran everything locally and it works great!

所以现在我想稍微上一点,我想在Heroku上托管我的服务器.我试过了,但是我遇到了一些问题...正如我所提到的,我只使用websockets,而不使用Flask,这意味着我需要指定主机ip/url和端口.但是当我在Heroku上托管服务器时,它说地址已在使用中".

So now I want to go up in a level a little bit, I want to host my server on Heroku. I tried but I have some problems with that... As I mentioned, I'm using only websockets and not Flask and that means that I need to specify a host ip/url and a port. But when I host the server on Heroku it says that "address already in use".

有人知道如何解决吗?

推荐答案

您可以使用ip"0.0.0.0"在heroku中进行托管,并从名为"PORT"的env变量中获取端口.在客户端上,您可以使用"wss://yourherokuapp.herokuapp.com/0.0.0.0"连接到Websocket服务器.确保在Procfile上,脚本以Web进程类型运行.

You can host in heroku by using the ip "0.0.0.0", and get the port from the env variable called "PORT". On the client you can connect to the websocket server using "wss://yourherokuapp.herokuapp.com/0.0.0.0". Make sure on your Procfile your script is running as a web process type.

这篇关于如何在没有Flask的Heroku上托管websocket应用python服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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