Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io - XHR polling vs flashsocket and websocket

Tags:

I use node.js and socket.io. I have a problem with the connection speed with socket.io. In Internet Explorer and Opera I have a problem with the connection speed. - When I use flashsocket or websocket. When I use the mode of transport-polling XHR connection is fast - in all browsers (IE, FF, Chrome, Opera).

What is the difference between the mode of transport - XHR-polling and flash / websocket? What is the best mode of transportation? How to optimize the connection speed is socket.io?

Thanks for the advice!

like image 400
Jenan Avatar asked Jan 10 '12 09:01

Jenan


People also ask

Is WebSocket better than polling?

WebSocket advantagesWebSockets keeps a unique connection open while eliminating the latency problems that arise with long polling. Full-duplex asynchronous messaging is supported so that both the client and the server can stream messages to each other independently.

What is XHR poll?

Websockets is the persistent connection that can be used to receive/send data without sequential order and without http header. Xhr-polling creates new request with http header and waits for answer with http header, also sequential order.

Does Socket.IO use polling?

First, Socket.IO creates a long-polling connection using xhr-polling. Then, once this is established, it upgrades to the best connection method available. In most cases, this will result in a WebSocket connection.

When should you not use a WebSocket?

Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.


1 Answers

I'd be surprised if the general speed of the connection over time was different between web browsers, but the reason you'll see a delay in the initial connection in Internet Explorer and in Opera is that native WebSocket support is not available as it's been disabled by default. So, if you choose FlashSocket then an additional Flash object (SWF file) will need to be downloaded before a connection is established.

WebSockets are being introduced in IE10 and in Opera they are available, but disabled by default.

What is the difference between the mode of transport - XHR-polling and flash / websocket?

  • XHR-polling - see http://en.wikipedia.org/wiki/Push_technology#Long_polling
  • FlashSocket connection - uses a Flash Socket object to establish a connection to the WebSocket server and communicates using the WebSocket protocol. This means there is interaction between Flash and JavaScript and also means an additional Flash object (SWF files) will need to be downloaded.

What is the best mode of transportation?

WebSockets for any Web Browser that natively supports it (Chrome, Firefox, Safari). If the Flash object (SWF file) is in the browser cache then connection should be fast. If it's not then there will be a delay. XHR Long-Polling is a good solution and will work cross browser but there are negatives:

  • between poll requests the data on display could be out of date (stale).
  • It's a less efficient connection method than a single TCP connection used by WebSockets since HTTP Long-Polling uses multiple connection to simulate bi-directional functionality
  • HTTP has an overhead which means additional header information is sent upon request and each subsequent request.

How to optimize the connection speed is socket.io?

(I'm pretty new to socket.io to this is just a suggestion)

I'd look at the configuring Socket.io docs and see if you can conditionally set the transports based on the browser that is connecting. Based on your experiences this could be:

  • Chrome, Firefox, Safari - WebSockets
  • IE, Opera - XHR-Polling
like image 199
leggetter Avatar answered Dec 04 '22 21:12

leggetter