socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
60.91k stars 10.09k forks source link

WebSocket connection to failed: Invalid frame header #2557

Closed lgg closed 8 years ago

lgg commented 8 years ago

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

server debug:

 socket.io:server incoming connection with id 7hnvZ1RkTsCgjyVVAAB- +4ms
 socket.io:client connecting to namespace / +3ms
 socket.io:namespace adding socket to nsp / +1ms
 socket.io:server incoming connection with id gOcFr2YHNcmSF9hqAAB_ +2ms
 socket.io:client connecting to namespace / +2ms
 socket.io:namespace adding socket to nsp / +1ms
 socket.io:namespace next called after client was closed - ignoring socket +74m

 socket.io:namespace next called after client was closed - ignoring socket +2ms

 socket.io:namespace next called after client was closed - ignoring socket +1ms

 socket.io:namespace next called after client was closed - ignoring socket +2ms

 socket.io:namespace next called after client was closed - ignoring socket +2ms

 socket.io:namespace next called after client was closed - ignoring socket +1ms

On client side: var socket = io({transports: ['websocket']}); //socket.io

What's wrong?

lgg commented 8 years ago

Server debug:

 socket.io:server incoming connection with id 1fX2a9tSW67s86bOAAAd +630ms
 socket.io:client connecting to namespace / +1ms
 socket.io:namespace adding socket to nsp / +1ms
 socket.io:server incoming connection with id ElBX5J56jGg2AL-RAAAe +3ms
 socket.io:client connecting to namespace / +2ms
 socket.io:namespace adding socket to nsp / +1ms
 socket.io:client client close with reason transport close +2ms
 socket.io:client client close with reason transport close +1ms
 socket.io:server incoming connection with id JM1_bp5eVOvNlyC-AAAf +2ms
 socket.io:client connecting to namespace / +2ms
 socket.io:namespace adding socket to nsp / +1ms
 socket.io:server incoming connection with id 5kOM-EtYOCmRrgZ7AAAg +4ms
 socket.io:client connecting to namespace / +2ms
 socket.io:namespace adding socket to nsp / +0ms
 socket.io:namespace next called after client was closed - ignoring socket +4ms

 socket.io:namespace next called after client was closed - ignoring socket +5ms

 socket.io:namespace next called after client was closed - ignoring socket +2ms

 socket.io:namespace next called after client was closed - ignoring socket +1ms
lgg commented 8 years ago

On network tab image

lgg commented 8 years ago

On client: image

On server:

var http = require('http'); //http module from node.js
var staticserver = require('node-static'); //http server for serving static files

//Create static serving server from 'client' folder
var file = new staticserver.Server('./client');

server = http.createServer(function (request, response) {
    request.addListener('end', function () {
        //
        // Serve files!
        //
        file.serve(request, response);
    }).resume();

    //Start socket.io server
    startSocket();
}).listen(port);

var options = {
    pingTimeout: 3000,
    pingInterval: 3000,
    transports: ['websocket'],
    allowUpgrades: false,
    upgrade: false,
    cookie: false
};
io = require('socket.io')(server, options);
lgg commented 8 years ago

I used node-static for serving files, with it socket.io doesn't work. With express or default node(http) it works.

Here an example: https://github.com/littleguga/websocket-test

rizkiaditya24 commented 6 years ago

@lgg is this issue solved? I have got the same problem

lgg commented 6 years ago

@rizkiaditya24 i used express.js instead of node-static

rrpatilcse commented 6 years ago

Same issue. Any one have solution for it? Error: WebSocket connection to 'ws://192.168.0.160/socket.io/?EIO=3&transport=websocket' failed: Invalid frame header

lgg commented 6 years ago

@rrpatilcse what server you are using? expressjs?

zengliangbigdata commented 6 years ago

i used nginx proxy django websoket service.now no way got it!throw "WebSocket connection to failed: Invalid frame header"

lgg commented 6 years ago

@zengliangbigdata show your nginx config, i think it could be troubles with proxy_pass

n3nikita commented 6 years ago

Same issue here.

VM41:164 WebSocket connection to 'ws://localhost:1337/socket.io/?EIO=3&transport=websocket&sid=dl2GgAoz02RW0OjCAAAC' failed: Invalid frame header

In the node.js console got this messages: info: Client disconnect: NaN error: Can not find client NaN on disconnect

I'm using Chrome and have this error. Everything works fine in IE.

carloverhamme commented 5 years ago

Same issue, I only get the error in the chrome console

gNull-ph commented 4 years ago

Same issue, I only get the error in the chrome console

SAME.. do you find any solution??

jclabrand commented 4 years ago

same!! someone tell me what's going on

SiddharthTiwari03 commented 4 years ago

Hi, I have encountered the same issue.

I am using NodeJS (LTS v12.18.1) with ExpressJS (v4.17.1) and Socket.io (v2.3.0).

Here is my server.js

`const express = require('express');

const app = express();

const server = require('http').createServer(app);

const io = require('socket.io')(server);

app.get('/',(req,res) =>{ // do something });

io.on('connection' ,socket => { // socket events handling });

server.listen(3000);`

Has anyone found a solution?

whoakashtyagi commented 3 years ago

Hi, I have encountered the same issue.

I am using NodeJS (LTS v12.18.1) with ExpressJS (v4.17.1) and Socket.io (v2.3.0).

Here is my server.js

`const express = require('express');

const app = express();

const server = require('http').createServer(app);

const io = require('socket.io')(server);

app.get('/',(req,res) =>{ // do something });

io.on('connection' ,socket => { // socket events handling });

server.listen(3000);`

Has anyone found a solution?

whoakashtyagi commented 3 years ago

same issue... please if anybody found solution.. then drop here

marcosybarraa commented 3 years ago

Same here

pdeivaraj commented 3 years ago

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

lgg commented 3 years ago

@marcosybarraa @pdeivaraj @whoakashtyagi

Im not sure, that yours' issues are the same to mine. I was trying to host static web-files with node-static and socket.io, changing libraries to express.js with socket.io helped to me. Also, there are some more "up to date" libraries for working with sockets, rather than socket.io (which seems a little bit abandoned)

Check this out: https://github.com/websockets/ws https://deepstream.io/ https://github.com/desertbit/glue

Also check this: https://github.com/facundofarias/awesome-websockets

Nabin0433 commented 3 years ago

same problem

pdeivaraj commented 3 years ago

@lgg thanks for your reference

kbinwant31 commented 3 years ago

Hi, I have encountered the same issue.

I am using NodeJS (LTS v12.18.1) with ExpressJS (v4.17.1) and Socket.io (v2.3.0).

Here is my server.js

`const express = require('express');

const app = express();

const server = require('http').createServer(app);

const io = require('socket.io')(server);

app.get('/',(req,res) =>{ // do something });

io.on('connection' ,socket => { // socket events handling });

server.listen(3000);`

Has anyone found a solution?

Same issue. Has anybody found a solution for this?

asheroto commented 3 years ago

Bump

mikecann commented 3 years ago

For me the answer was that I was connecting with a client that was version 2 and the server was running version 4. As per the docs I had to enable allowEIO3 on the server

trongkhoa1505 commented 2 years ago

For me the answer was that I was connecting with a client that was version 2 and the server was running version 4. As per the docs I had to enable allowEIO3 on the server

resolved

ShawnWhy commented 1 year ago

https://socket.io/docs/v4/server-options/#alloweio3 this worked for me, which is strange, because my socket.IO client is version 4

TheMixaDev commented 6 months ago

same issue, occured when trying to initialize on server PeerJS and SocketIO, starts fine if PeerJS disabled