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