On my localhost, my Node app is working flawlessly with socket.io. It connects once, and all of my messages get through. I'm now trying to deploy this to an AWS EC2 instance and getting problems with the web sockets. The server starts up, the main page loads fine, then when I click the button that connects to the web socket, it just loops through the connection code, but never calls the "doCoolThing" code, then starts connecting and disconnecting in a seemingly infinite loop. (see image below)
This is the app.js code:
io.on('connection', (socket) => {
console.log("connected");
socket.on('doCoolThing', (data) => {
console.log("doingCoolThing");
});
socket.on('disconnect', () => {
console.log("disconnect");
});
});
I am working in "socket.io": "~4.2.0" and have "websocket": "~1.0.34" (though I don't think I use it websocket).
Here is my client code:
const socket = io.connect('http://myurl:3000'); //I've also tried this with const socket = io.connect();
myButton.addEventListener("click", function () {
socket.emit("doCoolThing", data);
});
I don't see any cors errors, but I tried adding my url as described here: Socket.io + Node.js Cross-Origin Request Blocked which did not help.
My EC2 security is allowing all outgoing traffic and all incoming traffic from ports 80 and 3000 (the port the server is running on).
The repo in question can be found here: www.github.com/glenpierce/starTitan