123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- using CommonLang.Protocol;
- using CommonLang.Net;
- namespace CommonServer.Server
- {
- /// <summary>
- /// 描述一个链接
- /// </summary>
- public interface ISession : AbstractSession
- {
- /// <summary>
- /// Session ID
- /// </summary>
- string ID { get; }
- bool IsConnected { get; }
- /// <summary>
- /// 总共发送字节数
- /// </summary>
- long TotalSentBytes { get; }
- /// <summary>
- /// 总共接收字节数
- /// </summary>
- long TotalRecvBytes { get; }
- ISessionListener Listener { get; }
- /// <summary>
- /// 关闭此链接
- /// </summary>
- /// <param name="force"></param>
- /// <returns></returns>
- bool Disconnect(bool force);
- /// <summary>
- /// 发送消息【通知】
- /// </summary>
- /// <param name="message"></param>
- /// <returns></returns>
- bool Send(IMessage message);
- /// <summary>
- /// 发送消息【回馈】
- /// </summary>
- /// <param name="request"></param>
- /// <param name="response"></param>
- /// <returns></returns>
- bool SendResponse(IMessage request, IMessage response);
- /// <summary>
- /// 获取远端地址
- /// </summary>
- /// <returns></returns>
- string GetRemoteAddress();
- }
- /// <summary>
- /// 服务端监听器
- /// </summary>
- public interface ISessionListener
- {
- /// <summary>
- /// Session建立回调
- /// </summary>
- /// <param name="session"></param>
- void OnConnected(ISession session);
- /// <summary>
- /// Session关闭回调
- /// </summary>
- /// <param name="session"></param>
- /// <param name="force"></param>
- /// <param name="reason"></param>
- void OnDisconnected(ISession session, bool force, String reason);
- /// <summary>
- /// 错误【编解码或者网络底层】
- /// </summary>
- /// <param name="session"></param>
- /// <param name="err"></param>
- void OnError(ISession session, Exception err);
- /// <summary>
- /// 消息发送成功
- /// </summary>
- /// <param name="session"></param>
- /// <param name="message"></param>
- void OnSentMessage(ISession session, object message);
- /// <summary>
- /// 消息接收到
- /// </summary>
- /// <param name="session"></param>
- /// <param name="message"></param>
- void OnReceivedMessage(ISession session, object message);
-
- }
- }
|