Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs Socket.io Express failed to handshake after calling HTTP API #92

Open
1 task done
almgwary opened this issue Nov 21, 2017 · 0 comments
Open
1 task done

Comments

@almgwary
Copy link

You want to:

  • report a bug

Current behaviour

I am using SocketIo with Nodejs, Express server and MongoDB, I followed the documentation . it works fine when connecting multiple clients they can send messages to each other without any problem . when I made an Http request, I cannot connect any new clients and get this error.

socket.io.js:7370 WebSocket connection to
'ws://localhost:28232/socket.io/?userId=userAmr&EIO=3&transport=websocket&sid=wNTTgrUD-PSeNaIcAAAF'
failed: Error during WebSocket handshake: Unexpected response code:
400

the other connected users before the Http request can continue sending messages without any problem.

I debugged the Socket library and found the client socket request go to connect function then fire errorCode:1

This this my code

/**
 * Create Express server.
 */
const app = express();


// API endpoint
app.get('/api/test',(req,res)=>{
    res.status(200).send({test:"test"});
});



/**
 * Init socket
 */
const server = require('http').Server(app);
const io = require('socket.io')(server);


io.on('connection', (socket) => {

        // emit message to group
        socket.on('emitMessage', (data, callback) => {
                io.emit('emitMessage', data);
        });
});

This my question on stack overflow https://stackoverflow.com/q/47375814/6786941
To make the project work again removed this library till you fix it
This my answer on stack overflow https://stackoverflow.com/a/47411701/6786941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant