简体   繁体   中英

Connection is not stable in Socket.io

I'm using socket.io to build an application to share some html objects to all users connected to a room. But the users get disconnected automatically after some time. I would like to know how socket.io provides stable connection between server and connected user.

Disconnect may occur for several reasons, starting from network failures and ending with rather specific issues regarding load balancers. Here we cannot say we'll have 100% stable connection any time, some disconnects may occur in time to time.

If you happen to have disconnects, your app should know how to handle them. At first, you have to monitor disconnect , reconnect , reconnect_attempt and reconnect_failed events on client side (read events ) and ensure you are able to rejoin the room correctly after they were fired. There shouldn't be any additional code on server side unless you have to do something special on disconnect , for example, to delete a user from users array of some sort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM