Answer the question
In order to leave comments, you need to log in
Are HTTP requests allowed when using socket.io?
For educational purposes, I am developing an application for tracking sports results. I am using the socket.io library to receive result change messages from the server. Wanted to add registration and authorization. The question arose, how to do all this correctly? Would it be correct to use post requests for registration, and open a socket connection only after the user has logged in?
Answer the question
In order to leave comments, you need to log in
yes,
it makes sense to keep sockets only for data that changes dynamically and needs to be updated on the client, for other tasks it is redundant, where you can get by with regular http requests, it is better to use them
I couldn't read session and cookies on sockets. I sent an authkey with each socket request, which I issued to the user after authorization and checked whether there is such a user in the database. Or you can even cache in an external variable so as not to make a request to the database with each request.
So yes, I did authorization with a post request and sent authkey from cookies to sockets.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question