using IceCoffee.FastSocket.Tcp;
using langguanApi.Model;
using System.Net;
namespace langguanApi.Service.HJ212
{
    public class NetServer : TcpServer
    {
        /// 
        /// 收到数据事件
        /// 
        public event Action ReceivedData;
        /// 
        /// 发送数据事件
        /// 
        public event Action SendData;
        public NetServer(IPAddress address, int port, TcpServerOptions options = null)
            : base(address, port, options ?? new TcpServerOptions() { KeepAlive = true })
        {
        }
        public NetServer(string address, int port, TcpServerOptions options = null)
            : base(address, port, options ?? new TcpServerOptions() { KeepAlive = true })
        {
        }
        public NetServer(IPEndPoint endPoint, TcpServerOptions options = null)
            : base(endPoint, options ?? new TcpServerOptions() { KeepAlive = true })
        {
        }
        /// 
        /// 
        /// 
        /// 
        protected override TcpSession CreateSession()
        {
            return new NetSession(this);
        }
        /// 
        /// 引发收到数据事件
        /// 
        internal void RaiseReceivedData(NetSession netSession, NetPackage netPackage, string rawText)
        {
            ReceivedData?.Invoke(netSession, netPackage, rawText);
        }
        /// 
        /// 引发发送数据事件
        /// 
        /// 
        /// 
        /// 
        internal void RaiseSendData(NetSession netSession, NetPackage netPackage, string rawText)
        {
            SendData?.Invoke(netSession, netPackage, rawText);
        }
    }
}