Websocket Invalid frame header Error with local PeerJS Server
See original GitHub issueHi,
I succeed in using PeerJS with cloud server to make video conference thing, along with the websocket library ws. Now I tried to setup a local PeerJS Server, following the instruction from “Combining with existing express app” here, but It didn’t work and things acted weirdly. Below are my codes:
– Server –
//SET_UP
var express = require('express');
var app = express();
var ExpressPeerServer = require('peer').ExpressPeerServer;
var options = {
debug: true
};
var http = require('http');
var server = http.createServer(app);
var port = process.env.PORT || 9000;
app.get('*', function(req, res){
res.sendFile(__dirname + req.url);
});
app.use('/peerjs', ExpressPeerServer(server, options));
server.listen(port);
//Websocket
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer( {'server': server} );
wss.on('connection', function(ws){
ws.on('message', function(data){
// ...
});
ws.on('close', function(){
// ...
});
});
– Client –
peer = new Peer('123abc', { host: 'localhost', port: 9000, path:'/peerjs', debug:true});
// Get an ID from the PeerJS server
peer.on('open', function(id) {
console.log('My peer ID is: ' + id);
// Then connect to the socket server
connectSocket();
});
And this is what I got when I open webpage http://localhost:9000/index.html.
PeerJS: Socket open
WebSocket connection to 'ws://localhost:9000/peerjs/peerjs?key=peerjs&id=123abc&token=i1nay3ueh3tprpb9' failed: Invalid frame header
PeerJS: Socket closed.
PeerJS: ERROR Error: Lost connection to server.
It seems the PeerJS socket was connected once but shortly disconnect after. I guess it’s something with localhost but I don’t know what’s wrong. And it still happened if though I comment out my websocket server. Couldn’t figure out why. Please advice with any ideas and feedback. Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:5
Top Results From Across the Web
Websocket failed Invalid frame header - node.js - Stack Overflow
Everything works fine on localhost. but when i push/host it on heroku it shows me this error in the console of browser :...
Read more >Local PeerJS Server disconnected after connected, and then ...
WebSocket connection to 'ws://localhost:9000/peerjs/peerjs?key=peerjs&id=123abc&token=i1nay3ueh3tprpb9' failed: Invalid frame header. PeerJS: Socket closed.
Read more >Using WebSockets on Heroku with Node.js
We'll develop a simple application that shares the server's current time with the client via a persistent socket connection. Each application ...
Read more >Reason: CORS request did not succeed - HTTP | MDN
The HTTP request which makes use of CORS failed because the HTTP connection failed at either the network or protocol level. The error...
Read more >WebRTC 1.0: Real-Time Communication Between Browsers
If the content of description is not valid SDP syntax, then reject p with an RTCError (with errorDetail set to " sdp-syntax-error "...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Solved it! Should create two servers for each websocket with different ports. My code might not be efficient, but it works.
Thanks for your reply. My problem is another: WSS connection not working.