javascript - Problem with url with directory in socket.io connect
世界只因有你
世界只因有你 2017-05-16 13:35:59
0
1
723

Use socket.io to implement websocket. The current back-end link is like this: ws://103.31.201.1/some. Use nginx proxy to remove non-80 ports in the URL (mini programs are not allowed to carry ports, you know ), but in the actual request, socket.io always removes /some, and the requests are sent to ws://103.31.201.1. How to deal with this problem?

var socket = io.connect('ws://103.31.201.1/some')
socket.on('even_name',function(data){
   console.log(data);
})

The request URL sent becomes:

http://103.31.201.1/socket.io/?EIO=3&transport=polling&t=1492593587367-0

There is no directory path like /some in the url, causing the socket to be unable to connect

Supplement: Perfectly solved:

var socket = io.connect('ws://103.31.201.1', {path: '/some/socket.io'})
socket.on('even_name',function(data){
   console.log(data);
})

By default the path points to /socket.io, you can preset the path to add a directory

世界只因有你
世界只因有你

reply all(1)
滿天的星座

Hello, I encountered this problem you posted before. After configuring the path according to your solution, I found in the access log of nginx that the request return status code is 400. Do you know what is going on? /q/10. .. Problem with url with directory in socket.io connect

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template