WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400
Problem solved! I just figured out how to solve the issue, but I would still like to know if this is normal behavior or not.
It seems that even though the Websocket connection establishes correctly (indicated by the 101 Switching Protocols request), it still defaults to long-polling. The fix was as simple as adding this option to the Socket.io connection function:
{transports: ['websocket']}
So the code finally looks like this:
const app = express();
const server = http.createServer(app);
var io = require('socket.io')(server);
io.on('connection', function(socket) {
console.log('connected socket!');
socket.on('greet', function(data) {
console.log(data);
socket.emit('respond', { hello: 'Hey, Mr.Client!' });
});
socket.on('disconnect', function() {
console.log('Socket disconnected');
});
});
and on the client:
var socket = io('ws://localhost:3000', {transports: ['websocket']});
socket.on('connect', function () {
console.log('connected!');
socket.emit('greet', { message: 'Hello Mr.Server!' });
});
socket.on('respond', function (data) {
console.log(data);
});
And the messages now appear as frames:
working websockets
This Github issue pointed me in the right direction. Thanks to everyone who helped out!
"Error during WebSocket handshake: Unexpected response code: 400" while recording application using JMeter
As of current JMeter version 5.2.1 JMeter cannot either capture or properly proxy the WebSocket traffic so I would recommend splitting the recording in 2 parts:
- Before the login (including the login)
- After the login (to wit: login without proxy, then turn on proxy, then continue recording)
In any case all the WebSocket calls needs to be captured separately using a 3rd-party sniffer tool like Fiddler or Wireshark and then properly simulated using JMeter WebSocket Samplers plugin
Related Topics
How to Open a Url Link from JavaScript Inside a Google Apps Script HTML Google Site Gadget
How to Share and Edit Global Variables Between Two JavaScript Node Runs
Passing Variable from One Js to Another Js File in Nodejs
How to Force Clients to Refresh JavaScript Files
Draw a Connecting Line Between Two Elements
How to Hide the Parent Div If All Its Child Div Are Hidden
How to Add a Dynamic Action That Will Redirect to Another Page by Executing JavaScript Code
How to Change Size of Mat-Icon on Angular Material
How to Check a Radio Button in the Table Row Based on That Column Header
How to Enable Scrolling on Website That Disabled Scrolling
Is It Any Limit for Post Data Size in Ajax
Checking for Null Is Not Working for Ajax Json Data
How to Add a New Object (Key-Value Pair) to an Array in JavaScript
Open Html5 Date Picker on Icon Click
Ngx-Datatable Set Column Width Dynamically
How to Extract the User Name from an Email Address Using JavaScript
Select Li Element With Arrow Keys (Up and Down) Using JavaScript (Jquery)
How to Make One Observable Sequence Wait for Another to Complete Before Emitting