建立与heroku应用程序的socket.io连接
我在heroku 上托管我的socket.io 服务器,并在本地主机上运行应用程序的客户端。在前端,我像这样建立了 socket.io 连接:
const socket = io("https://<my-app-name>.herokuapp.com:5000/");
后端看起来像这样:
const port = 5000;
const io = require("socket.io")(port, { cors: { origin: "*" } });
io.on("connection", (socket) => { console.log(socket.id) }
但是连接无法建立,并且在浏览器的控制台中我收到此错误:
GET https://<my-app-name>.herokuapp.com:5000/socket.io/?EIO=4&transport=polling&t=Nym-K6b net::ERR_CONNECTION_TIMED_OUT
顺便说一句,当我运行时它工作得很好我的本地主机上的服务器端也是如此。
I am hosting my socket.io server on heroku and I am running the client-side of the application on localhost. On the frontend I establish the socket.io connection like this:
const socket = io("https://<my-app-name>.herokuapp.com:5000/");
And the backend looks like this:
const port = 5000;
const io = require("socket.io")(port, { cors: { origin: "*" } });
io.on("connection", (socket) => { console.log(socket.id) }
But the connection won't establish and in the console of my browser I receive this error:
GET https://<my-app-name>.herokuapp.com:5000/socket.io/?EIO=4&transport=polling&t=Nym-K6b net::ERR_CONNECTION_TIMED_OUT
BTW it works just fine when I'm running the server-side on my localhost too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://socket.io/docs /v4/troubleshooting-connection-issues/#the-server-is-not-reachable
https://socket.io/docs/v4/troubleshooting-connection-issues/#the-server-is-not-reachable