0

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.

bayethierno
  • 159
  • 1
  • 12
  • 1
    Already answered: http://stackoverflow.com/questions/16392260/which-websocket-library-to-use-with-node-js –  Dec 09 '16 at 09:26

2 Answers2

2

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.

Lewis
  • 14,132
  • 12
  • 66
  • 87
  • 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 – bayethierno Dec 09 '16 at 09:00
  • 1
    @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. – Lewis Dec 09 '16 at 09:18
  • 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 – bayethierno Dec 10 '16 at 07:55
  • @Lewis could you elaborate why? – pinkpanther May 12 '20 at 19:24
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.

John Pangilinan
  • 953
  • 1
  • 8
  • 25
  • 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 – bayethierno Dec 09 '16 at 08:15
  • 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. – John Pangilinan Dec 09 '16 at 08:23
  • Oki thx for your response i will dig to know about performance before making choice – bayethierno Dec 09 '16 at 08:58