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!
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.
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.
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.
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.
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?
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:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With