In Breeze IM, when a client goes offline, other clients can perceive that the user is offline and turn their avatar icon Gray.
Perceptual connection Drop, is the NETWORKCOMMS framework built-in functionality, the server through heartbeat detection of a connection dropped, will be maintained from the NETWORKCOMMS internal connection list to remove the connection, and trigger the corresponding delegate.
We're going to handle a connection drop, just register the Networkcomms.appendglobalconnectionclosehandler method to
The server-side code is as follows:
// If a client is offline, this method is triggered Networkcomms.appendglobalconnectionclosehandler (handleconnectionclosed);
Processing method of a client's offline user
//handling a client offline situation Private voidhandleconnectionclosed (Connection Connection) {Try { varTempuserid =""; Lock(synclocker) {//find the user ID corresponding to the network connection in the user dictionary foreach(varKvinchUsermanager) { //If you are shutting down a network connection that is the same as a user's network connection, locate the user if(KV. Value = =connection.ConnectionInfo.NetworkIdentifier) {Tempuserid=KV. Key; Break; } } if(Tempuserid! ="") { //if the found user ID is not empty, the item is removed from the user dictionary if(Usermanager.containskey (Tempuserid)) {//When the connection is closed, remove the user from the User ManagerUsermanager.remove (Tempuserid); } } } //send notifications to other clients informing them of a user's downline if(Tempuserid! ="") {userstatenotify (Tempuserid,false); } //a message should be sent to all other users online } Catch(Exception ex) {logtools.logexception (ex,"networkcomms_connectionclosed"); } }
www.networkcomms.cn
Www.cnblogs.com/networkcomms
Chat program based on TCP communication Breeze IM (C # Open source)-Technical Analysis (iii) client Downline