kerryjiang / SuperSocket

SuperSocket is a light weight, cross platform and extensible socket server application framework.
Apache License 2.0
3.95k stars 1.15k forks source link

SuperSocket 1.6 的 EasyClient 偶尔接受数据不全 #486

Open 12343954 opened 3 years ago

12343954 commented 3 years ago

服务端发送byte[]

public class CommandBuilder
    {
        //消息包头部为01
        private const ushort HeartMsg = 1;
        //心跳包头部为02
        private const ushort HeaderHeart = 2;

        /// <summary>
        /// 发送消息---List<byte>
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] BuildMsgCmd(string msg)
        {
            var arr = new List<byte> { };
            var byteHeader = BitConverter.GetBytes(HeartMsg).Reverse().ToList();

            var byteMsg = Encoding.UTF8.GetBytes(msg);
            var byteLength = BitConverter.GetBytes((ushort)byteMsg.Length).Reverse().ToList();

            arr.AddRange(byteHeader);
            arr.AddRange(byteLength);
            arr.AddRange(byteMsg);

            return arr;
        }

var config = new SuperSocket.SocketBase.Config.ServerConfig()
{
    Name = "SuperSocketServer",
    ServerTypeName = "SuperSocketServer",
    ClearIdleSession = false, //60秒执行一次清理90秒没数据传送的连接
    ClearIdleSessionInterval = 60,
    IdleSessionTimeOut = 90,
    MaxRequestLength = 1024 * 1024 * 10, //最大包长度
    ReceiveBufferSize = 4196,// 新增配置
    SendBufferSize = 8192,// 4096,
    Ip = "Any",
    Port = port,
    MaxConnectionNumber = 1000, //10000,//最大允许的客户端连接数目, 
};
session.TrySend(msg, 0, msg.Length);

客户端接收数据

public EasyClient<MySuperSocket.MyPackageInfo> client { get; set; } = new EasyClient<MySuperSocket.MyPackageInfo>();
client.ReceiveBufferSize = 1024 * 1024 * 10;

数据量在2640字节,偶尔会有接不全的情况,具体就是,json 反序列化时,有属性,没值,然后以”}“结束,很奇怪

DavidZhiXing commented 3 years ago

查看一下你序列化的后的string有没有问题