我在试着把前端和Phoenix一号分开。3(localhost:4000),我在localhost:3000上运行React。
我这辈子都没法和菲尼克斯联系上我得到错误:
WebSocket connection to 'ws://localhost:4000/socket/websocket?token=undefined&vsn=2.0.0' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
我使用以下客户端:
let socket = new Socket("ws://localhost:4000/socket", {params: {token: window.userToken}})
socket.connect();
// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("coin:lobby", {});
channel
.join()
.receive("ok", resp => {
console.log("Joined successfully", resp);
})
.receive("error", resp => {
console.log("Unable to join", resp);
});
我可以设法连接使用wsta在终端,我收到了良好的React。我认为这可能是某种CORS问题,但我已经实现了cors_plug
Elixlib,我仍然有这个问题。有什么建议吗
1条答案
按热度按时间k97glaaz1#
你必须先安装phoenix客户端
npm install phoenix --save
我也遇到了同样的问题,用同样的代码解决了。
请参考此link