59 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
using IceCoffee.FastSocket.Tcp;
 | 
						|
using langguanApi.Model;
 | 
						|
using System.Net;
 | 
						|
 | 
						|
namespace langguanApi.Service.HJ212
 | 
						|
{
 | 
						|
    public class NetServer : TcpServer
 | 
						|
    {
 | 
						|
        /// <summary>
 | 
						|
        /// 收到数据事件
 | 
						|
        /// </summary>
 | 
						|
        public event Action<NetSession, NetPackage, string> ReceivedData;
 | 
						|
        /// <summary>
 | 
						|
        /// 发送数据事件
 | 
						|
        /// </summary>
 | 
						|
        public event Action<NetSession, NetPackage, string> 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 })
 | 
						|
        {
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        protected override TcpSession CreateSession()
 | 
						|
        {
 | 
						|
            return new NetSession(this);
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 引发收到数据事件
 | 
						|
        /// </summary>
 | 
						|
        internal void RaiseReceivedData(NetSession netSession, NetPackage netPackage, string rawText)
 | 
						|
        {
 | 
						|
            ReceivedData?.Invoke(netSession, netPackage, rawText);
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 引发发送数据事件
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="netSession"></param>
 | 
						|
        /// <param name="netPackage"></param>
 | 
						|
        /// <param name="rawText"></param>
 | 
						|
        internal void RaiseSendData(NetSession netSession, NetPackage netPackage, string rawText)
 | 
						|
        {
 | 
						|
            SendData?.Invoke(netSession, netPackage, rawText);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |