Open 12343954 opened 3 years ago
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 反序列化时,有属性,没值,然后以”}“结束,很奇怪
查看一下你序列化的后的string有没有问题
服务端发送byte[]
客户端接收数据
数据量在2640字节,偶尔会有接不全的情况,具体就是,json 反序列化时,有属性,没值,然后以”}“结束,很奇怪