123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonLang.Protocol;
- using System.Collections.Specialized;
- using CommonLang.Net;
- namespace CommonServer.Server
- {
- /// <summary>
- /// 服务器监听器
- /// </summary>
- public interface IServerListener
- {
- /// <summary>
- /// 服务器初始化回调
- /// </summary>
- /// <param name="server"></param>
- void OnInit(IServer server);
- /// <summary>
- /// 服务器关闭回调
- /// </summary>
- void OnDestory();
- /// <summary>
- /// 一个链接建立成功
- /// </summary>
- /// <param name="session"></param>
- /// <returns></returns>
- ISessionListener OnSessionConnected(ISession session);
- }
- /// <summary>
- ///
- /// </summary>
- public interface IServerFactory
- {
- IServer CreateServer(INetPackageCodec codec);
- }
- public interface IServer
- {
- /// <summary>
- /// 客户端连接套接字
- /// </summary>
- string ClientConnectString { get; }
- /// <summary>
- /// 获取编解码器
- /// </summary>
- INetPackageCodec PackageCodec { get; }
- /// <summary>
- /// 获取当前已连接数
- /// </summary>
- int SessionCount { get; }
- /// <summary>
- /// 启动服务器
- /// </summary>
- /// <param name="port"></param>
- /// <param name="listener"></param>
- void Open(IDictionary<string, string> config, IServerListener listener);
- /// <summary>
- /// 关闭服务器
- /// </summary>
- void Dispose();
- /// <summary>
- /// 广播消息
- /// </summary>
- /// <param name="message"></param>
- void Broadcast(IMessage message);
- /// <summary>
- /// 服务器是否有此链接
- /// </summary>
- /// <param name="session"></param>
- /// <returns></returns>
- bool HasSession(ISession session);
- /// <summary>
- /// 根据 Session ID 获取链接
- /// </summary>
- /// <param name="sessionID"></param>
- /// <returns></returns>
- ISession GetSessionByID(string sessionID);
- /// <summary>
- /// 获取所有链接
- /// </summary>
- /// <returns></returns>
- IEnumerable<ISession> GetSessions();
- long TotalSentBytes { get; }
- long TotalRecvBytes { get; }
- void SetEmulateLaggingMS(int min, int max);
- void GetEmulateLaggingMS(out int min, out int max);
- }
- }
|