question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error during WebSocket handshake: Unexpected response code: 400

See original GitHub issue

I’m using npm peer@0.2.10 with socket.io using the Express server.

my package.json dependencies

"dependencies": {
   "express": "^4.17.1",
   "peer": "^0.2.10",
   "socket.io": "^1.4.6"
 }

The error does not happen in peer@0.2.8 and my simple code is as follow.

server.js

const express = require('express');
const PeerServer = require('peer').PeerServer;
const ExpressPeerServer = require('peer').ExpressPeerServer;
const socket_io = require('socket.io');

const app = express()
const port = 3000

app.use(function(req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
	next();
});

app.get('/', (req, res) => {
	res.sendFile('/var/www/html/mypeer.html');
})

const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`))

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

peerserver.on('error', (client) => {
	console.log('error');
});

peerserver.on('connection', (client) => {
	console.log(`The client ${client} is connected`);
});


var rec_sockio = socket_io.listen(server);
rec_sockio.sockets.on('connection', function(socket) {
	console.log('socket is connected', socket.id);
});

mypeer.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Peer Test</title>
</head>
<body>

	<script src="https://unpkg.com/peerjs@1.0.2/dist/peerjs.min.js"></script>
	<script type="text/javascript" src="http://192.168.33.10:3000/socket.io/socket.io.js"></script>
	<script>
		const peer = new Peer({host: '192.168.33.10', port: 3000, path: '/myapp'});
		console.log(`peer`, peer);

		peer.on('error', function(err) {
			console.log(`err`, err);
		});

		var sock_client = io.connect('192.168.33.10:3000');
		sock_client.on('connect', function() {
			console.log(`sock_client connect`);
		});
	</script>
</body>
</html>

I got this error

WebSocket connection to 'ws://192.168.33.10:3000/socket.io/EIO=3&transport=websocket&sid=tQ5aa4lRzqMlGmX7AAAB' failed: Error during WebSocket handshake: Unexpected response code: 400

The error seems having problem with the transport websocket but polling seems okay.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mafikescommented, Jun 19, 2020

The same issue. Server “peer”: “^0.5.3” and client 1.2.0. 😕

2reactions
cgfarmer4commented, May 17, 2020

same 1.2 and 0.5.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection failed: Error during ... - Stack Overflow
WebSocket connection failed : Error during WebSocket handshake: Unexpected response code: 400 · Ask Question. Asked 5 years, 11 months ago.
Read more >
Error during WebSocket handshake: Unexpected ... - GitHub
Why error after migrate from v2.2.0 to v2.4.0 ??? Error during WebSocket handshake: Unexpected response code: 400.
Read more >
Error during WebSocket handshake: Unexpected response ...
WebSocket connection to 'wss://mydomain/openvidu' failed: Error during WebSocket handshake: Unexpected response code: 400 - Issues with deployment - OpenVidu.
Read more >
Error during WebSocket handshake: Unexpected response code
I updated server from 2017 R2 to 2019 R1. and tried to open my web app. my web app uses mobile SDK and...
Read more >
Got connection failed: Error during WebSocket handshake ...
Help~ Got connection failed: Error during WebSocket handshake: Unexpected response code: 400. I have a problem connecting to the photon server ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found