E
E
Egor Telnov2019-08-27 16:16:51
JavaScript
Egor Telnov, 2019-08-27 16:16:51

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

2 answer(s)
R
RidgeA, 2019-08-27
@telnov_magic

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

R
RookDeveloper, 2019-08-27
@RookDeveloper

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 question

Ask a Question

731 491 924 answers to any question