SuperSocket 服务端接受慢
各位老铁,我用网络上的例子,做一个接收测试,单个客户端,每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实时接收。