简体   繁体   English

如何配置websocket?

[英]How to configure websocket?

On the local server, these settings work在本地服务器上,这些设置有效

CHAT_WS_SERVER_HOST = '0.0.0.0'
CHAT_WS_SERVER_PORT = 3000
CHAT_WS_SERVER_PROTOCOL = 'ws'

And the chat is working fine, but on Heroku there is an error(Chrome):聊天工作正常,但在 Heroku 上有一个错误(Chrome):

WebSocket connection to 'ws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkin' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接到“ws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkin”失败:连接建立错误:net::ERR_CONNECTION_REFUSED

On Heroku I use such settings:在 Heroku 上,我使用这样的设置:

CHAT_WS_SERVER_HOST = '0.0.0.0'
CHAT_WS_SERVER_PORT = os.environ['PORT'];
CHAT_WS_SERVER_PROTOCOL = 'ws'

Python code websocket = new WebSocket(base_ws_server_path + '{{ request.session.session_key }}/' + opponent_username); Python 代码websocket = new WebSocket(base_ws_server_path + '{{ request.session.session_key }}/' + opponent_username);

JS code on client websocket = new WebSocket(base_ws_server_path + 'jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/' + opponent_username);客户端websocket = new WebSocket(base_ws_server_path + 'jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/' + opponent_username);上的 JS 代码websocket = new WebSocket(base_ws_server_path + 'jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/' + opponent_username);

Fihish ws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkinws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkin

I read that this is a problem because of the certificate (wss \\ https), but I don't use him now... or with the wrong IP我读到这是因为证书(wss \\ https)的问题,但我现在不使用他......或者IP错误

Upd_1更新_1 错误 仍处于 CONNECTING 状态

无法在“WebSocket”上执行“发送”:仍处于连接状态。

The IP address 0.0.0.0 refers to the local server. IP 地址0.0.0.0指的是本地服务器。 When your browser connects to that address, it will reach the computer where the browser is running (eg your laptop).当您的浏览器连接到该地址时,它将到达运行浏览器的计算机(例如您的笔记本电脑)。 Since you want it to connect to your Heroku app, you need to replace the value 0.0.0.0 with the hostname for your Heroku app, eg your-app-name.herokuapp.com .由于您希望它连接到您的 Heroku 应用程序,您需要将值0.0.0.0替换为您的 Heroku 应用程序的主机名,例如your-app-name.herokuapp.com This way, the browser will connect over the internet to your Heroku app instead.这样,浏览器将通过互联网连接到您的 Heroku 应用程序。

The URL in the browser should look like ws://your-app-name.herokuapp.com:...浏览器中的 URL 应该类似于ws://your-app-name.herokuapp.com:...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM