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

167
Views
socket.io connections failing after integrating peer server in my code

hi as you know public server is down so i tried to host my on peer server i already had a nodejs/express server up for chat ... so i tried to integrate peer server on my chat server

here is simplified version of my code

const  env = require('dotenv').config({ path: '.env' })
const express = require('express');
const { ExpressPeerServer } = require('peer');
const fs = require('fs');
const app = express();
const https = require('https');
const http = require('http');

let server ;

if(env.parsed.PROTOCOL === 'https')
{
    // server =  create https server
}
else
{
     server = http.createServer( app);
}


const { Server } = require("socket.io");
const io = new Server(server);

const peerServer = ExpressPeerServer(server, {
    debug: true
});
app.use('/peerjs', peerServer);


io.sockets.on('connection', function(socket) {
    console.log(`@ connection | socket -> ${socket.id} |`);
});


var PORT = env.parsed.PORT  || 8080

server.listen(PORT, () => {
    console.log(`listining to port ${PORT} `);
});

the problem is after adding peer server to my code i cant establish any socket.io connection to the server ... i get no errors in the server i just get the client side error

WebSocket connection to 'ws://localhost:8080/socket.io/?EIO=4&transport=websocket' failed: Invalid frame header

server is up and working , if i type localhost:8080 in the browser i will get the response

if i remove peer server code it would work fine

i can move peer server to separate code and run on a different port but i prefer to keep it in this code

any idea why this happening ?

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

0

According to this issue, it's not possible to run socket.io and a PeerJS server on the same Express(/http(s) server) instance.

You should be able to start a separate PeerJS server from the same code file, as explained here:

const { PeerServer } = require('peer');

const peerServer = PeerServer({ port: 9000, path: '/myapp' });
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!