- Home /
Node.js + Socket.io + Heroku
I have an Node.js Server with Socket.io driving socket based interactions with the Unity Client. Additionally, I have a Web Application that connects to the same server. The Web App sends RESTful calls to the Server, which in turn broadcasts to the Unity Client.
When I run everything locally, everything works great. Web App can talk to the game, Game Client updates correctly.
Moving the server side code over to Heroku however is a different story. Nothing has changed other than the connection URL in SocketIOComponent.
Example connection URL for Heroku: ws://blooming-chamber-76501.herokuapp.com:47960/socket.io/?EIO=4&transport=websocket
I am guessing it is CrossDomain something something, but I am at a total loss after 10 hours of Googling and Foruming. Note: I did read a note about how Sockets do not work with Heroku, but got a basic Socket.io example running just fine: https://quiet-fortress-68565.herokuapp.com/
Help, advice, guidance, anything would be appreciated.
Friend I am with this problem. Do you can post your code server?
Answer by scottbromander · Nov 23, 2016 at 07:33 AM
Figured it out! After three days of research, it turns out the connection URL needs to specifically target port 80.
Example: ws://blooming-chamber-76501.herokuapp.com:80/socket.io/?EIO=4&transport=websocket
@scottbromander I don't know how did you come up with this solution but thank god you did!
I was beginning to go berserk!!!
After I've read your solution I've came across documentation which specifies that Heroku port forward their 80 to the designated port which is being chosen when the app is deployed.
Thumbs UP! Jacob.
Answer by chin13577 · Mar 12, 2018 at 11:55 AM
Hey ! I found the way!!.
if you run server in the localhost. the url should have ":port" example
ws://127.0.0.1:47960/socket.io/?EIO=4&transport=websocket
**but if you have deployed to heroku the url must delete ":port"
ws://your-project-name-76501.herokuapp.com/socket.io/?EIO=4&transport=websocket
it's work!
Your answer
Follow this Question
Related Questions
How to stream audio from unity app to the web browser? 0 Answers
How do I connect to a server in LAN from a different computer? I'm using socket.io and nodejs 1 Answer
How to set namespace in packet of socketIO using unity3d 1 Answer
Socket Io Client sent messages are not received at the Node Js server. 1 Answer