Websocket is automatically disconnected from the background connection when it is being used:

Cause analysis:

  • 1. Add a log to the webSocket shutdown callback and observe the output of the log
ws.onclose = function (e) {
    console.log('WebSocket disconnected:' + e.code + ' ' + e.reason + ' ' + e.wasClean)
    console.log(e)
}
Copy the code

Closeevent. code: Error code closeEvent. reason: Cause closeEvent. WasClean: Indicates whether the connection is normal

Close the status code table

Status code The name of the describe
0-999. Keep field
1000 CLOSE_NORMAL Normally closed
1001 CLOSE_GOING_AWAY The terminal exits, the server fails, or the browser hops away from the page
1002 CLOSE_PROTOCOL_ERROR Terminal connection due to protocol error
  • 2. The cause is 1000, and the connection is normally disconnected. Multiple tests revealed that the webscoket automatically disconnects after clicking on the page’s download function. Will now
  • 3. Check the download code and find:
<a style='color:#a0b883; text-decoration:underline; cursor:pointer; ' 
download= 'Error log.xlsx'
href = 'http://ip:port/group1/M00/03/8C/CsQVW1yI1wqAVLDZAAAruXJmym45.xlsx'>Error log download</a>
Copy the code
  • 4. According to the above a tag, it turns out that the page left because of the download of a tag.

Solutions:

This can be solved by adding a target attribute to the A tag. <a target='_blank' 
 style='color:#a0b883; text-decoration:underline; cursor:pointer; ' 
 download= 'Error log.xlsx' 
 href = 'http://ip:port/group1/M00/03/8C/CsQVW1yI1wqAVLDZAAAruXJmym45.xlsx'> Error log download </a>Copy the code