• 获取会话的连接和断开事件


    获取会话的连接和断开事件

     

    关键字: 连接事件, 断开事件, OnSessionStarted, OnSessionClosed, NewSessionConnected, SessionClosed

    AppSession 的虚方法 OnSessionStarted() 和 OnSessionClosed(CloseReason reason)

    你可以覆盖基类的虚方法 OnSessionStarted() 和 OnSessionClosed(CloseReason reason) 用于在会话连接和断开时执行一些逻辑操作:

    public class TelnetSession : AppSession<TelnetSession>
    {
        protected override void OnSessionStarted()
        {
            this.Send("Welcome to SuperSocket Telnet Server");
            //add your business operations
        }
    
        protected override void OnSessionClosed(CloseReason reason)
        {
            //add your business operations
        }
    }
    

    AppServer 的两个事件: NewSessionConnected 和 SessionClosed

    订阅事件:

    appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
    appServer.SessionClosed += new SessionHandler<AppSession, CloseReason>(appServer_SessionClosed);
    

    定义事件处理方法:

    static void appServer_SessionClosed(AppSession session, CloseReason reason)
    {
        Console.WriteLine("A session is closed for {0}.", reason);
    }
    
    static void appServer_NewSessionConnected(AppSession session)
    {
        session.Send("Welcome to SuperSocket Telnet Server");
    }
    
     

    © 2018 - GetDocs.Net - Hosted by BuyVM

  • 相关阅读:
    tomcat配置用户角色权限
    jenkins集成maven
    centos7安装maven
    jenkins凭证插件的安装和基本使用
    Jenkins用户权限管理
    虚拟机NAT模式配置静态IP
    制作sentinel docker镜像
    docker安装nacos
    Tkinter
    neo4j导入csv文件
  • 原文地址:https://www.cnblogs.com/liuslayer/p/8624348.html
Copyright © 2020-2023  润新知