Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Why my socket.io video chat won't work on heroku?

I'm new to WS and Heroku and all that... so i have this code

//this sets up client-side sockets i guess

    import {io} from 'socket.io-client';
    
    const options = {
      "force new connection": true,
      reconnectionAttempts: "Infinity", 
      timeout : 10000, 
      transports : ["websocket"]
    }
    
const socket = io('/', options)

export default socket;

and for the server side

    const path = require('path');
    const express = require('express');
    const app = express();
    const server = require('http').createServer(app);
    const io = require('socket.io')(server);
    const {version, validate} = require('uuid');
    
    const ACTIONS = require('./src/socket/actions');
    const PORT = process.env.PORT || 3001;
///more code

When deployed to heroku this results in this app https://lit-atoll-99067.herokuapp.com/ and the chrome console says :

WebSocket connection to 'wss://lit-atoll-99067.herokuapp.com/socket.io/?EIO=4&transport=websocket' failed: WebSocket is closed before the connection is established.

So i ran out of ideas. but i guess this has to be about port or something... dunno really. Any ideas are welcome!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you need to pass the full URL at the client-side but you only passed the "/" only example:-

import {io} from 'socket.io-client';
    
const options = {
  "force new connection": true,
   reconnectionAttempts: "Infinity", 
   timeout : 10000, 
   transports : ["websocket"]
}
// here need to pass the full url
const socket = io('https://example.com/', options)

export default socket;

And for the server side try this

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);

io.on('connection', (socket) => {
  console.log('a user connected');
});

server.listen(3000, () => {
  console.log('listening on *:3000');
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!