We have a front on angular and backing to node.js.

Before that, I always used the socket.io library for the web transport and did not know grief.

But now we are starting a new project in which our server will give data not only to the web application, but also to the mobile application. Mobile application is written by other contractors. And it turns out that now I cannot use socket.io. it transports via pseudo-web sockets and the mobile phone guys won't be able to connect to my channel. And using the js-library on a mobile platform is not the best solution and they certainly won't go for it and will do it right.

Please advise stable, fast, supported by developers, with a concise syntax, working with "real" websocket libraries.

  • 3
    write on clean web sites! on client side is clear, on ws - nörbörnën

1 answer 1

And it turns out that now I cannot use socket.io. it transports via pseudo-web sockets and the mobile phone guys won't be able to connect to my channel.

1) "pseudo-websocket"

It seems to me that socket.io uses the most common sockets, just the first connection happens over http , for negotiation. As a result of the negotiation, it turns out to switch to sockets (the client supports them) or stay on http (pooling).

2) will not be able to connect

https://www.npmjs.com/package/socket.io

Some implementations in other languages ​​are also available:

  • Java
  • C ++
  • Swift
  • Dart

3) if you still want to use only ws

As far as I understand, the answer given below tells how to use socket.io without http pooling

https://stackoverflow.com/a/28240802/4794368

There are two types of "upgrades" happening with socket.io. First (in socket.io 1.0+), socket.io starts the polling request. Then, it will try to actually initiate a webSocket connection.

You can prevent the initial http polling by this client:
var socket = io({transports: ['websocket'], upgrade: false});
This will prevent polling connections. If you want to polish, then you can add this to the server:
io.set('transports', ['websocket']);
But, if you’re not connecting at all. So, it should never be matched.


UPD1:

socket.io/docs

By default, a long-polling connection is established first, then upgraded to “better” transports (like WebSocket).

and here github.com/socketio/.../transports list of protocols

  • very instructive, thank you) - muturgan