Error "Error connecting to the web site" using socket.io on an ec2 instance?

I have this web application written using express and socket.io using node.js, the application runs on the local host, but when I click on my ec2 server, it connects for about 20 seconds, then disconnects and then connects again and so on ...

gives me an error in node console like

warn - websocket connection invalid info - transport end 

SERVER

 app = express() server = http.createServer(app) io = require('socket.io').listen(server) 

CUSTOMER

 socket = io.connect() 

I know that the problem is not in my code, because I fully tested the web application on the local host, so the only problem is where does this code work, which is my ec2 instance?

+6
source share
4 answers

Make sure you use the latest versions of node, express and socket.io on your ec2. In addition, provide some information about the versions currently used on both your local computer and the ec2 instance.

+2
source

There can be many possible reasons why you might get this error:

  • You are using a browser that partially or does not support websites. You can check if your browser supports websites here .
  • Using a proxy server that does not support websocket. If between your client and your node server there is some server (load balancer) that does not support websocket.
  • You are using socket.io version 0.9.1 / 0.9.1-1. This is an error message for this version. So, upgrade to the latest version of socket.io, which is 0.9.14.
  • The connection to the browser is through a firewall / block.
  • Code related issue.
+4
source

On your local computer, you do not need to deal with network latency, problems with NAT or firewalls. Running on EC2 you have it all.

Web sockets are relatively new and unstable. So first, make sure you are using the latest versions (and let us know what they are). It is possible that the version of socket.io installed on your local computer is different from the version installed on your EC2 server.

+1
source

If no activity occurs during these 20 seconds before losing the connection, one possibility is that keep-alive is set too low.

See https://groups.google.com/forum/?fromgroups=#!topic/socket_io/RUv70BguZ-U for a similar problem. The solution was to use the heart rate to keep the connection open.

A bit more on socket.io heartbeats if you are not already using them: Advantage / disadvantage of using socketio heartbeats

+1
source

Source: https://habr.com/ru/post/943594/


All Articles