using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using Team.Communicate.EventArg; using Team.Communicate.State; namespace Team.Communicate.Server { public interface ITeamTcpServer : IDisposable { /// /// 服务器是否正在运行 /// bool IsRunning { get; } /// /// 监听的IP地址 /// IPAddress Address { get; } /// /// 监听的端口 /// int Port { get; } /// /// 通信使用的编码 /// Encoding Encoding { get; set; } /// /// 启动服务器 /// void Start(); /// /// 启动服务器 /// /// /// 服务器所允许的挂起连接序列的最大长度 /// void Start(int backlog); /// /// 停止服务器 /// void Stop(); /// /// 发送数据 /// /// 接收数据的客户端会话 /// 数据报文 void Send(TcpClientState state, byte[] data); /// /// 发送数据 /// /// 接收数据的客户端会话 /// 数据报文 Task SendAsync(TcpClientState state, byte[] data); /// /// 指定IP地址发送数据 /// /// /// void Send(string ip, byte[] data); /// /// 指定IP地址发送数据 /// /// /// Task SendAsync(string ip, byte[] data); /// /// 异步发送数据至指定的客户端 /// /// 客户端 /// 报文 void Send(TcpClient client, byte[] data); /// /// 异步发送数据至指定的客户端 /// /// 客户端 /// 报文 Task SendAsync(TcpClient client, byte[] data); void BroadToClient(string msg); Task BroadToClientAsync(string msg); /// /// 与客户端的连接已建立事件 /// event EventHandler ClientConnected; /// /// 与客户端的连接已断开事件 /// event EventHandler ClientDisconnected; /// /// 接收到数据事件 /// event EventHandler DataReceived; /// /// 发送数据前的事件 /// event EventHandler PrepareSend; /// /// 数据发送完毕事件 /// event EventHandler CompletedSend; /// /// 网络错误事件 /// event EventHandler NetError; /// /// 异常事件 /// event EventHandler OtherException; /// /// 关闭一个与客户端之间的会话 /// /// 需要关闭的客户端会话对象 void Close(TcpClientState state); /// /// 关闭所有的客户端会话,与所有的客户端连接会断开 /// void CloseAllClient(); /// /// Performs application-defined tasks associated with freeing, /// releasing, or resetting unmanaged resources. /// } }