Tcp-based chat program breeze IM (c # Open Source ),

Source: Internet
Author: User

Tcp-based chat program breeze IM (c # Open Source ),

In breeze IM, when a client is offline, other clients can perceive that the user has been offline and turn the Avatar icon into gray.

The disconnection of the sensor connection is a built-in function of the networkcomms framework. When the server detects a connection disconnection through heartbeat detection, the server deletes the connection from the connection list maintained in networkcomms and triggers the corresponding delegate.

To handle a disconnection, you only need to register the NetworkComms. AppendGlobalConnectionCloseHandler method.

The server code is as follows:

// If a client is offline, this method is triggered NetworkComms. AppendGlobalConnectionCloseHandler (HandleConnectionClosed );

Offline processing of a user on the client

// Process a client offline private void HandleConnectionClosed (Connection connection Connection) {try {var tempUserID = ""; lock (syncLocker) {// find the user ID foreach (var kv in userManager) corresponding to the network connection in the user dictionary {// if the network connection to be closed is the same as the network connection of a user, find the user if (kv. value = connection. connectionInfo. networkIdentifier) {tempUserID = kv. key; break ;}} if (tempUserID! = "") {// If the user ID is not empty, delete this option from the user dictionary if (userManager. containsKey (tempUserID) {// when the connection is closed, delete the user userManager from the User Manager. remove (tempUserID) ;}}// send a notification to other clients to notify them that a user is offline if (tempUserID! = "") {Userstatenoworkflow (tempUserID, false) ;}// a message should be sent to all other online users} catch (Exception ex) {LogTools. logException (ex, "NetworkComms_ConnectionClosed ");}}

Www.networkcomms.cn

Www.cnblogs.com/networkcomms

 

Related Article

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.