Emre
Emre

Reputation: 565

Which one is best for chat app ? Web socket or Send request every 3 seconds

I am making chat app on react-native. I am using socket.io for this but socket.io sometimes not working successful. I would like to change send request to server side every 3 seconds.

I just send request for one chat id

Which one is best? If i use send request in every 3 seconds , will happen any problem from server side

Upvotes: 2

Views: 1645

Answers (2)

Mosè Raguzzini
Mosè Raguzzini

Reputation: 15831

Maybe long polling (not polling, it is different behaviour, with long polling an api call can stay pending until response is available) is an option but WebSocket are far preferable. Responses are faster, it costs less resources serverside, less bandwidth, you can subscribe to multiple streams and so on.

Here you can valutate some metrics:

enter image description here enter image description here enter image description here enter image description here

Ref: https://blog.feathersjs.com/http-vs-websockets-a-performance-comparison-da2533f13a77

Upvotes: 2

Neil Slater
Neil Slater

Reputation: 27207

socket.io scales better, and has better performance, than any polling HTTP request mechanism. When working well, it will also have faster response times than 3 seconds - it may not seem long, but actually it may be noticeable to users.

If your chat app is for a low number of users, then a polling mechanism is easier to implement and should work just fine.

If you intend to scale your application to a large number of users, you will need socket.io or a similar subscribe/push mechanism to connected clients.

Upvotes: 1

Related Questions