Reputation: 136
I have this situation where I need to store data in a database and emit an event to only specific sockets. This can be done in two ways :
Emit an event from the client side, listen to that event on the sever side, store the data and emit the event to sockets we want.
Send a http request to the server, where I store the data and emit the event to sockets.
I was wondering which one of these methods is efficient and is there any better solution to the use case than these two.
Upvotes: 0
Views: 277
Reputation:
I would say that if you are already using SocketIO, it might be a good idea to go with option 1, emiting an event from the client side. I am not sure how your application is structured, but I presume that when you use SocketIO in the first place, you will do all your server side communication through there anyway.
HTTP requests have an obvious overhead to them as they - at the very least - send headers to the server.
However when you begin long polling you'll always need to make sure that it doesn't create a massive load on the server. Now I see that you have node.js
in your subject, which I hope is what you use. If that is the case, then this will not create any problems as node.js
is very good in handling these requests at almost no cost of system resources.
Disclaimer: I am no expert on the raw technical details which is best or not, I am a mere developer with an opinion. I don't mind down voting, but please let me know why so we can all learn.
Upvotes: 1