Reputation: 2019
The code works locally. When I push it to heroku there are problems.
I am certain the ports are right. I don't know what the issue is. I suspect that it's an issue with the client side code. I tried changing it to https:// as opposed to http:// but that made it stop working locally and on heroku.
Error on FF:
Firefox can't establish a connection to the server at ws://localhost/socket.io/?EIO=2&transport=websocket.
Error on Chrome:
WebSocket connection to 'ws://localhost/socket.io/?EIO=2&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
//on the client side
socket = io.connect("http://localhost", {port: PORT, transports: ["websocket"]});
//on the server side
var port = Number(process.env.PORT || 4000);
var express = require("express");
var logfmt = require("logfmt");
var app = express();
app.set('views', __dirname + '/views');
var server = require('http').createServer(app)
io = require("socket.io").listen(server);
io.set("transports", ["websocket"]);
io.set("polling duration", 10)
Upvotes: 2
Views: 2010
Reputation: 46
First, if you want your client to connect to you heroku app, you should use your heroku app host instead of localhost.
var host = location.origin;
io.connect(host, {port: PORT, transports: ["websocket"]});
Upvotes: 3