1

i want to developp a messenger web app in realtime with nodejs and i wanted to know what's the best choice between websocket and socket.io for the server and the client side.my concerning is performance, like if i use websocket in both server and client side or socket.io what would be more performant. THX THX.

1

2 Answers 2

3

socket.io was built on top of WebSocket. So there is no chance for it to be any faster than WebSocket. I think the role of socket.io to WebSocket is quite similar to the role of jQuery to Javascript. socket.io has fallback solutions when WebSocket is not available. So basically, it supports more browsers. I personally prefer to use WebSocket over socket.io. It's not because of performance advantage, it's actually about having more controls over the application architecture.

Sign up to request clarification or add additional context in comments.

4 Comments

nice response but look like socket.io give you more flexibility in sending evenement likt with emit you can give a name for an evenement and use that same iname in the server
@user3741442 It's actually quite the opposite. socket.io forces you to use the event model for delivering messages. I personally think it's not a good choice of architecture.
but sometime its better to have that since you dont need to put the type of event in the message that you are sending, let's say you have an chat app you need to send login information through the socket and also new message for exemple if you use websocket you have to put the event type in the data that you are sending
@Lewis could you elaborate why?
1

Don't compare Websockets over socket.io, Websocket is a protocol while socket.io is a socket framework (javascript) that uses Websocket as one of it's protocol. Socket.io (client) will use Websocket in communicating whenever it's supported, as a fallback, it will use the old-fashioned polling method when Websocket is not supported by the clients device.

3 Comments

You are right and i knew that my concerning is performance, like if i use websocket in both server and client side or socket.io what would be more performant. THX
As i have said, websocket is a protocol, and socket.io is a framework that uses websocket as one of it's protocol. socket.io makes the use of the websocket api to connect/send/receive data, socket.io make it easier to use the websocket api through it's own api.
Oki thx for your response i will dig to know about performance before making choice

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.