Chat program based on TCP communication Breeze IM (C # Open source)-Technical Analysis (iii) client Downline

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.