D
D
Dmitry Volkhontsev2018-07-03 08:24:54
Node.js
Dmitry Volkhontsev, 2018-07-03 08:24:54

Will SSE work or leave WebSocket?

Good day.
There is an intranet web application, at the moment it functions as follows - the server part is written in node.js using express and socket.io. To send any changes from the client to the server, regular post-requests are used, and after making changes, the server sends these changes using socket.io rooms to a specific list of users.
Now we want to rewrite this service using Koa.js and http2, and we want to understand whether SSE can replace websockets in our case or not? This is not entirely clear from the materials on the Internet. Specifically, I did not find information on whether it is possible to do something like subscriptions to channels or mailing to other connected users ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-07-03
@DarkDD

Both SSE and WS are protocols over http, both can work over http / 2 and have multiplexing
. But there are differences between them:
WS provides two-way communication, after establishing a handshake, either side can send messages, the protocol is binary, all messages are encoded into binary message- frame, which requires additional libraries on the server side (on the browser this comes in a standard api), but it allows you to transfer both binary and text data
SSE - one-way communication, only from the server to the client, the client can only transmit data in url when opening a connection, then only the server broadcasts, the protocol is text, if there is binary data, they will have to be wrapped in base64 (for example), from the server's point of view, this is normal GET request, which the server does not close, but simply sends data to the http body in a special format, periodically flushing connections (ideally after each message)
Everything else, like rooms, etc. - library add-ons and no more
In the case of koa - by default, it completes the request when the promise from the last middleware resolves, SSE will have to bypass this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question