Header frame is not valid

I have been working on developing a real-time application using NodeJS as my server and Socket.IO to enable live updates.

However, I encountered an error message that reads:

 WebSocket connection to 'wss://localhost:1234/socket.io/?EIO=3&transport=websocket' failed: Invalid frame header

I've attempted various solutions such as switching from https to http and downgrading the Socket.IO version, yet none of these changes have resolved the issue. I am seeking assistance in identifying the root cause of this problem so that I can troubleshoot it within my application. I am determined to resolve this without resorting to alternative COMET protocols.

Answer №1

Ensure that the socket.io and socket.io-client versions match on both the server and client sides.

Answer №2

It turned out that the problem was caused by my error of initializing the server with socket.io twice.

Answer №3

In my case, the issue arose from connecting with a client using version 2 while the server was running version 4. Following the instructions outlined in the documentation, I needed to activate the allowEIO3 setting on the server.

Answer №4

Encountered a problem while utilizing create-react-app and launching it with "npm run start" to access the live refresh local version during development. The default websocket path used was /ws, which clashed with my app that also utilized this path. Consequently, when employing setupProxy.js with http-proxy-middleware, both paths were forwarded to the api server, resulting in invalid frame headers.

To resolve this issue, I modified the websocket route within the web app to something distinct like /websocket instead. Additionally, I adjusted the setupProxy.js file as follows:

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
    app.use(
        // Avoid using `/ws` as it conflicts with create-react-app's hotrefresh socket.
        createProxyMiddleware('/websocket', {
            target: 'http://localhost:3000',
            ws: true,
            changeOrigin: true,
        })
    );
};

Answer №5

Switched to using the standalone server for socket.io and it solved the issue that I was facing. Originally, I had added it to the express server. This snippet of code resolved the problem..

const io = require("socket.io")();

//listening on a different port
io.listen(4000);

Answer №6

I encountered a similar problem while using socket.io-client. Fortunately, I was able to resolve the issue by following the steps below.

If you are experiencing this issue, you can attempt to specify the transports option as only websocket in the client:

io.connect(url, { transports: ['websocket'] }); // the default is ['polling', 'websocket']

You can refer to this link for more information: https://github.com/socketio/socket.io-client/issues/1097#issuecomment-301301030

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I want to create a custom jQuery slider totally from scratch

Greetings everyone, I have been tasked with creating a slider using only HTML / jQuery code. Here is the template: And here is the HTML code for the template above: <div id="viewport-container"> <section id="sliding-container"> & ...

Navigating pages with Jqueryor Using J

Currently, I am utilizing jQuery and AJAX to retrieve data from a remotely stored PHP file on a server. After successfully fetching the initial page and displaying the outcomes in an HTML table, I've encountered a new challenge. My goal now is to fetc ...

What is the best way to generate a new div element when the content exceeds the preset height of the current div?

CSS .page{ width: 275px; hight: 380px; overflow: auto; } HTML <div class="page">dynamic text</div> Is there a way to automatically create new div elements when dynamic text overflows past the fixed height of the init ...

Preventing document.getElementById from throwing errors when the element is null

Is there a way to handle null values returned by document.getElementById in JavaScript without adding if statements or checks to the code? I'm looking for a solution that allows the execution of subsequent JavaScript calls even after encountering a nu ...

Error in NodeJS: 'Cannot alter headers once they have been sent.'

My project involves developing an app with Express that fetches tweets from Twitter. Each API call retrieves 200 tweets (or fewer if there are less than 200) and in total, I need to retrieve 1800 tweets. To achieve this, I use a time interval to make multi ...

Encountering a problem with AngularJS ui router templates

I have defined the following routes in my project: $stateProvider .state('access', { abstract: true, url: '/access', templateUrl: 'login.html' }) .state('access.signin', { ...

Are there any alternative approaches to handling frequent database updates in web development aside from using Websockets/AJAX for coding?

Currently, I'm in the process of developing an HTML and Javascript game and looking to implement a feature that displays the player's gold balance on the screen. The goal is to have this balance decrement by 1 every time the player clicks on a sp ...

Display a specific tab section upon clicking using jQuery or JavaScript

Hello everyone! I am completely new to JavaScript. I have added a tab slider to my HTML with 3 categories in the tab menu: All, Creative, and Branding. How can I show a div after clicking on one of the list items? I have assigned classes to the list items ...

Is there a way to display the entire stack trace in Mocha when testing Promises and an error occurs?

Imagine I have a small specification like this: describe("feature", () => { it("does something", () => { return myPromiseBasedFn().then(result => { expect(result).to.eql(1); }); }); }); At the moment, when the promise is reject ...

Search in the Firestore database for documents that have a field containing a reference to another document. Once those results are found, use the reference to conduct a second query

In an attempt to optimize the query that delivers details of all events a participant has attended, I have restructured my database schema. Events with participants are now linked through a subEvent subcollection in the users collection, storing document r ...

What causes req.sessions to show an empty object instead of the expected value?

I've been grappling with a small issue while learning express.js. I am struggling to save sessions in the browser so that users don't have to log in every time they visit. I am using cookie-session for this purpose. When I send the login data fro ...

Is the automatic garbage collection of components a built-in feature of

Consider this scenario, where I have the following HTML document: <html> <head>... including all the necessary js and css files here...</head> <body> <div class="placeholderForExtPanel"></div> </b ...

Having trouble getting $compile to work in an injected cshtml file with Angular

Summary I am currently working on a large application where everything is designed to be very generic for easy expansion. One of the components I am focusing on is the dialog. Before suggesting alternatives like using ngInclude or angular templates, let m ...

Issue with Webstorm not automatically updating changes made to JavaScript files

On my HTML page, I have included references to several JavaScript files such as: <script type="text/javascript" src="MyClass.js"></script> When debugging in WebStorm using a Python SimpleHTTPServer on Windows with Chrome, I am able to set bre ...

Calculating the mean value of the numbers provided in the input

I'm struggling with calculating the average of numbers entered through a prompt window. I want to display the numbers as I've done so far, but combining them to find the average is proving difficult. Here's the code I have: <html> &l ...

Can POST data be acquired in socket io and express js?

Currently, I am using a web service to send POST data from an application at regular intervals. My challenge is to retrieve this POST data on the client side (index.html) and then pass it to a JavaScript function. Any ideas or recommendations on how to a ...

"Put Jest to the test by running it with the Express

Currently, I am in the process of learning how to build an API with TypeScript and experimenting with testing it using the Jest framework. When utilizing a basic Express application like app = express() supertest(app) everything works smoothly. However, ...

The preventDefault method is failing to prevent the default action when placed within a

I am having trouble using preventdefault to stop an action. I'm sorry if the solution is obvious, but I can't seem to locate the mistake. Why isn't it preventing the link from being followed? Here is a link to my jsfiddle: http://jsfiddle.ne ...

Leverage the power of npm packages within a Flutter mobile app's webview

I am currently developing a Flutter mobile app and I am interested in incorporating an npm package that utilizes web3.js and offers additional custom features. My understanding is that Dart code in Flutter is not compiled to JavaScript, so I have been lo ...

How to implement PayPal integration in PHP

I am currently working on integrating the paypal payment system into a website dedicated to pet adoption. Initially, I had a basic code structure that was functional. However, after making some modifications and additions to the code, it no longer redirect ...