React Socket IO is not connected to heroku server
up vote
0
down vote
favorite
I'm trying to get the server or port of heroku;this works fine on the localhost, but the socket.io feature doesn't work on heroku.
this is the error i get on heroku.
websocket.js:120 WebSocket connection to
'wss://localhost:5000/socket.io/?EIO=3&transport=websocket' failed:
Error in connection establishment: net::ERR_CONNECTION_REFUSED
p.doOpen @ websocket.js:120
App.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var PORT = process.env.PORT || 5000;
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
io.on('connection', (socket)=>{
console.log(socket.id);
socket.on('SEND_MESSAGE', (data)=>{
io.emit('RECEIVE_MESSAGE', data);
})
});
http.listen(PORT,function(){
console.log('listening on port %s',PORT);
});
Chat.js
// this has to be something other than localhost, it needs to work vice versa.
this.socket = socketIOClient('localhost:5000');
this.socket.on('RECEIVE_MESSAGE', function(data){
addMessage(data);
});
node.js sockets heroku
add a comment |
up vote
0
down vote
favorite
I'm trying to get the server or port of heroku;this works fine on the localhost, but the socket.io feature doesn't work on heroku.
this is the error i get on heroku.
websocket.js:120 WebSocket connection to
'wss://localhost:5000/socket.io/?EIO=3&transport=websocket' failed:
Error in connection establishment: net::ERR_CONNECTION_REFUSED
p.doOpen @ websocket.js:120
App.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var PORT = process.env.PORT || 5000;
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
io.on('connection', (socket)=>{
console.log(socket.id);
socket.on('SEND_MESSAGE', (data)=>{
io.emit('RECEIVE_MESSAGE', data);
})
});
http.listen(PORT,function(){
console.log('listening on port %s',PORT);
});
Chat.js
// this has to be something other than localhost, it needs to work vice versa.
this.socket = socketIOClient('localhost:5000');
this.socket.on('RECEIVE_MESSAGE', function(data){
addMessage(data);
});
node.js sockets heroku
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to get the server or port of heroku;this works fine on the localhost, but the socket.io feature doesn't work on heroku.
this is the error i get on heroku.
websocket.js:120 WebSocket connection to
'wss://localhost:5000/socket.io/?EIO=3&transport=websocket' failed:
Error in connection establishment: net::ERR_CONNECTION_REFUSED
p.doOpen @ websocket.js:120
App.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var PORT = process.env.PORT || 5000;
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
io.on('connection', (socket)=>{
console.log(socket.id);
socket.on('SEND_MESSAGE', (data)=>{
io.emit('RECEIVE_MESSAGE', data);
})
});
http.listen(PORT,function(){
console.log('listening on port %s',PORT);
});
Chat.js
// this has to be something other than localhost, it needs to work vice versa.
this.socket = socketIOClient('localhost:5000');
this.socket.on('RECEIVE_MESSAGE', function(data){
addMessage(data);
});
node.js sockets heroku
I'm trying to get the server or port of heroku;this works fine on the localhost, but the socket.io feature doesn't work on heroku.
this is the error i get on heroku.
websocket.js:120 WebSocket connection to
'wss://localhost:5000/socket.io/?EIO=3&transport=websocket' failed:
Error in connection establishment: net::ERR_CONNECTION_REFUSED
p.doOpen @ websocket.js:120
App.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var PORT = process.env.PORT || 5000;
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
io.on('connection', (socket)=>{
console.log(socket.id);
socket.on('SEND_MESSAGE', (data)=>{
io.emit('RECEIVE_MESSAGE', data);
})
});
http.listen(PORT,function(){
console.log('listening on port %s',PORT);
});
Chat.js
// this has to be something other than localhost, it needs to work vice versa.
this.socket = socketIOClient('localhost:5000');
this.socket.on('RECEIVE_MESSAGE', function(data){
addMessage(data);
});
node.js sockets heroku
node.js sockets heroku
asked Nov 7 at 9:05
BARNOWL
4611419
4611419
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
This is a hardcoded workaround
app.js
this.socket = socketIOClient.connect(HEROKU_PATH_HERE, {secure: true});
if(!this.socket){
this.socket = socketIOClient('localhost:5000');
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This is a hardcoded workaround
app.js
this.socket = socketIOClient.connect(HEROKU_PATH_HERE, {secure: true});
if(!this.socket){
this.socket = socketIOClient('localhost:5000');
}
add a comment |
up vote
0
down vote
This is a hardcoded workaround
app.js
this.socket = socketIOClient.connect(HEROKU_PATH_HERE, {secure: true});
if(!this.socket){
this.socket = socketIOClient('localhost:5000');
}
add a comment |
up vote
0
down vote
up vote
0
down vote
This is a hardcoded workaround
app.js
this.socket = socketIOClient.connect(HEROKU_PATH_HERE, {secure: true});
if(!this.socket){
this.socket = socketIOClient('localhost:5000');
}
This is a hardcoded workaround
app.js
this.socket = socketIOClient.connect(HEROKU_PATH_HERE, {secure: true});
if(!this.socket){
this.socket = socketIOClient('localhost:5000');
}
answered Nov 7 at 9:25
BARNOWL
4611419
4611419
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186306%2freact-socket-io-is-not-connected-to-heroku-server%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown