v7.3.2018.0614   重构高性能资源池,减少GC压力,增加线程池,让异步任务得到平等竞争CPU的机会
大石头 authored at 2018-06-14 17:56:44
1.00 KiB
X
using System;
using System.IO;
using NewLife.Net.Sockets;

namespace NewLife.Net.Application
{
    /// <summary>Discard服务器。抛弃所有收到的数据包,不做任何响应</summary>
    public class DiscardServer : NetServer
    {
        /// <summary>实例化一个Discard服务</summary>
        public DiscardServer()
        {
            // 默认9端口
            Port = 9;

            Name = "Discard服务";
        }

        /// <summary>已重载。</summary>
        /// <param name="session"></param>
        /// <param name="stream"></param>
        protected override void OnReceive(INetSession session, Stream stream)
        {
            if (stream.Length == 0) return;

            if (stream.Length > 100)
                WriteLog("Discard {0} [{1}] {2}...", session.Remote, stream.Length, stream.ReadBytes(1000).ToStr());
            else
                WriteLog("Discard {0} [{1}] {2}", session.Remote, stream.Length, stream.ToStr());
        }
    }
}