How does the websocket server disconnect automatically?

  • spring-boot-websocket
Websocket is implemented in the form of

spring-boot-websocket stomp.

  • Business scenario
After the payment is successfully scanned on the

page, the back-end websocket notifies the front-end page to jump.

  • question

the QR code is automatically closed without payment within 2 minutes, and then the connection can be closed, so how can the back-end service close the connection automatically?

Jul.30,2021

websocket is an extended communication protocol based on the tcp protocol, so it supports two-way communication.

since you intend to time the server, you can send a request to close the connection to the client 2 minutes after the server has not paid for it. The client automatically closes and triggers the onclose event of websocket , and websocket connection closes.

how to write the server code depends on how your server websocket is implemented. For a normal self-implemented server, you only need to send a control frame of 0x8 to the client, and the client shuts down after a while.


Why not consider that the front-end js is timed for 2 minutes and jump away without receiving the payment after the time?


not too much java , see if you can give the client a close control message.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c43e-2c2f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c43e-2c2f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?