SuperSocket 服务端接受慢

wangawang520 2019-04-08 09:37:43
各位老铁,我用网络上的例子,做一个接收测试,单个客户端,每300ms发一条消息给Server,一共发500条。
运行时发现,客户端把500条消息发完后,服务器端才收到将近150条消息,再过8分钟后,所有的500条消息才能收完。
服务器配置如下:
private void MainForm_Load(object sender, EventArgs e)
{
var config = new SuperSocket.SocketBase.Config.ServerConfig()
{
Name = "SSServer",
ServerTypeName = "SServer",
ClearIdleSession= true, //60秒执行一次清理90秒没数据传送的连接
ClearIdleSessionInterval = 60,
IdleSessionTimeOut = 90,
MaxRequestLength = 2048, //最大包长度
Ip = "127.0.0.1",
Port = 50001,
MaxConnectionNumber = 60000,
};
app = new MyServer(app_NewSessionConnected, app_SessionClosed);
LogHelper.SetOnLog(new LogHelper.LogEvent((m) =>
{
txtAll.Text = string.Join(" ", m, "\r\n");
txtAll.Select(txtAll.TextLength, 0);
txtAll.ScrollToCaret();
}));
app.Setup(config);
if (!app.Start())
{
LogHelper.WriteLog(string.Format("Socket {0}:{1}启动失败,请检查权限或端口是否被占用!", config.Ip, config.Port));
}
}
接收Command:
private int Action = 3;
public override string Name
{
get { return Action.ToString(); }
}
/// <summary>
/// 上行
/// </summary>
public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
{
LogHelper.WriteLog(session.NickName + " !! " + requestInfo.Body);
Push(session, "已收到文本");
}

客户端发送如下:
//每5秒发一次心跳
var idx = 0;
sendTimer = new System.Timers.Timer(300);
sendTimer.Elapsed += new System.Timers.ElapsedEventHandler((s, x) =>
{

if (idx < 500)
{
idx++;
if (client.IsConnected && cbHeart.Checked)
{
var arr = new List<byte> { 0, 3 };
var txt = System.Text.Encoding.UTF8.GetBytes("this client "+ txtMsg.Text+" test : " + txtMsg.Text + "0"+idx);
arr.Add((byte)(txt.Length / 256));
arr.Add((byte)txt.Length);
arr.AddRange(txt);
client.Send(arr.ToArray());

LogHelper.WriteLog("发送数据:C"+ txtMsg.Text +" idx = "+idx+" : " + DataHelper.ByteToHex(arr.ToArray(), arr.Count)+idx);
//txtMsg.Text = "";
}
}
});
sendTimer.Enabled = true;
sendTimer.Start();


从Log来看,服务端将近1s才收到一条消息。各位大手帮忙看下,怎么才能做到SuperSocket实时接收。
...全文
419 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2019-04-09
  • 打赏
  • 举报
回复
1.我们不认条,我们认字节 2.同样我们不认触发一次,我们认解析出包一次 底层有算法,他会合并包。不是说发2条,就会触发2次。 so,告诉我们你一共发了多少字节,一共收了多少字节。然后总耗时多少秒
  • 打赏
  • 举报
回复
谁知道你的服务器如何设计开发的?你贴的代码没说明任何设计。
stherix 2019-04-08
  • 打赏
  • 举报
回复
日志占用了太多时间 建议去掉 或者换成log4net

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧