Some netizens are unable to leave the chat room through normal channels due to line disconnection, crashes, etc., resulting in the number of people online not being displayed properly! The solution is generally
1 Create a file of the number of online people, which saves the id/pass/time of the online person, where time is the last update time
2 Every once in a while when the chat program is running normally Update your id/pass/time to notify the system that you are online, usually 1-2 minutes
3. The system scans the list of online people every grid for a period of time to find those who have exceeded the specified time (such as 5 minutes). The updated id is confirmed to have been abnormally offline
4 The number of people online is the number of lines in the file, and the list is the line data
My chat room that is now available for download is implemented using this method !
This method has a relatively simple process, but the issue of file sharing becomes critical when there are many people. Through practice, I found a method that consumes very little system resources and can solve the problem of sharing very well!
The specific ideas are as follows:
1 Create a useronline subdirectory to store online personnel data
2 Each person who enters creates a file with the user name in it named file. The content is empty!
3 When the chat program is running normally, it updates the files in its subdirectory at regular intervals
4 The system determines whether the number of users is offline based on the update time of the files in the directory
5 The number of people online is the number of files in the directory, and the list is the file name
Advantages: Everyone can update their own files without affecting other people, and there is no sharing problem!
Since it can be scanned every 5 minutes, it consumes very little resources!
This technology will be used in my new chat room! ! !