My Twitter streaming app using Socket.io works okay when visiting the site with the IP address and port, but live streaming throws an error, when using the domain name to access the site. 🤔
Try the links below, and open up the developer tools, to see the error
Hundreds of socket errors following this format:
WebSocket connection to
'ws://sentiment-sweep.com/socket.io/?EIO=3&transport=websocket&sid=guBmeCqsOr22CTsWAAC0'
failed: WebSocket is closed before the connection is established.
Initially a few of the above socket errors, but then affter 10-15 seconds the app starts to work fine
I made this Node app for a University project few years back. I keep it updated. It uses Socket.io and the Twitter API to stream live Tweets, calculate the sentiment and display results visually using D3. I use NGINX for port forwarding.
For reference, here is my git repo: https://github.com/Lissy93/twitter-sentiment-visualisation
Recently I made a small HTML/ CSS change, and updated a couple of dependencies, and that's when this strange socket.io issue started
io.connect();
with no params to connectHas anyone seen an issue similar to this before? Any suggestions, comments or answers would be greatly appreciated - thanks very much in advance.
Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.
The most common cause of Websocket error is when you connect to DSS through a proxy. Websockets is a fairly recent protocol and many enterprise proxies do not support it. The websocket connection will not establish and you will see this message.
Once the original connection has been closed, you need to create a new websocket object with new event listeners: var SERVER = 'ws://localhost:8080' var ws = new WebSocket(SERVER) ws.
Found the solution, and it was in fact simple! Posting the answer here, to help others facing a similar issue, because I was totally stuck on this for 2 days!
My issue was caused by a dependency update.
According to the release notes:
The new (V 2.0.0) major release brings several performance improvements, but also snuck into the bottom of the release notes was this:
This release is not backward-compatible, due to:
- A breaking change related to utf-8 encoding in engine.io-parser (socketio/engine.io-parser#81)
- an update to make the socket id on the client match the id on the server-side (socketio/socket.io-client#1058)
Please note that if you are using a self-signed certificate, rejectUnauthorized now defaults to true (socketio/engine.io-client#558).
Here's the full V2 release notes: https://github.com/socketio/socket.io/releases/tag/2.0.0
Make your app https, or sign your own requests, as per documentation. As a quick fix though, I just downgraded back to socket.io V 1.7.0 and it works perfectly 😏
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