Solve the problem of "GET http://localhost:xxxx/socket.io/?EIO&transport=polling net::ERR CONNECTION_REFUSED"

The project uses socket.io, the front end is react and the back end is node.js+expresss

There is no problem in the local test. When deployed to the server, an error is reported as shown in the title, and the client cannot connect to the server.

After consulting the document, I realized that the real server ip address must be written to deploy to the server, and the hostname cannot be written.

The original code is as follows:

io.socket = io('ws://localhost:4000') 

Then modify the code in react as follows:

 io.socket = io('ws://xxxx.xxxx.xxxx.xxxx:4000') 

The message can be sent and received successfully, and the problem is solved at this point.

Guess you like

Origin blog.csdn.net/a1059526327/article/details/106906059