'SocketIO server using NodeJS and 400 http server (Bad Request)

here goes a quite interesting question about SocketIO and NodeJS.

The server is based on version 2.4.x of NodeJS version of SocketIO, and the client is an mobile client (Android and iOS). This is how a successful flow should be:

  1. GET method from client (request URL is https://example.com/?EIO=3&transport=polling)
  2. server answers including socket ID (HTTP responde code is 200)
  3. client emits messages using the socket ID and POST method
  4. server answers accordingly (HTTP responde code is 200)

Steps 3 and 4 repeats while client emits messages (login, retrieve data from the server, etc).

The problem appears on point 4. The client emits a message and the server sends HTTP code 400 (Bad Request). Given this problem appears in the very beginning of the cycle, users can't log in.

I've read in many posts that 400/Bad Requests errors in SocketIO context happens given to CORS. However, the client receives a 200/OK before such error codes.

How can this possible? Any suggestions?

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source