(求救)由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
部分代码如下:,请教高手指点
private void startListen()
{
// 通讯服务于应用服务之间连接数
int nConnectNum = 10;
// 检测连接状态时间间隔,单位:秒
int nWaitTime = 10;
TcpCli g_cli_try = new TcpCli(new Coder(Coder.EncodingMothord.CETECH));
try
{
do
{
if (clientTable.Count < nConnectNum && g_cli_try.TryConnect(serConfig.AppServerIP, serConfig.AppServerPort))
{
while (clientTable.Count < nConnectNum)
{
TcpCli g_cli = new TcpCli(new Coder(Coder.EncodingMothord.CETECH));
//定义服务器的3个事件
g_cli.ReceivedDatagram += new NetEvent(RecvData);
g_cli.DisConnectedServer += new NetEvent(ClientClose);
g_cli.ConnectedServer += new NetEvent(ClientConn);
g_cli.SendData += new NetEvent(SendData);
//try
//{
g_cli.Connect(serConfig.AppServerIP, serConfig.AppServerPort);
//}
//catch
//{
// this.Stop();
//}
Thread.Sleep(100);
}
}
else
{
for (int i = 0; i < nWaitTime; i++)
{
Thread.Sleep(1000);
}
}
}
while (_isRun);
do
{
Thread.Sleep(100);
}
while (_quitThread);
}
catch (Exception ex)
{
CloseException();
pubText("Error: " + ex.Message);
CatchException(this, new MessageEventArgs("Cin.startListen ex:" + ex.Message));
}
}
红色部分出现异常:“Cin.sendToApp ex:由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。”,先通过关闭,然后再启动该监听线程,但又会同样的错误
/// <summary>
/// 异常关闭
/// </summary>
private void CloseException()
{
_isRun = false;
g_msgQueue.Clear();
CloseAllClient();
}
/// <summary>
/// 关闭所有的客户端会话,与所有的客户端连接会断开
/// </summary>
private void CloseAllClient()
{
ArrayList al = new ArrayList();
if (clientTable != null)
{
foreach (int strClient in clientTable.Keys)
{
al.Add(strClient);
}
for (int i = 0; i < al.Count; i++)
{
try
{
CloseClient(int.Par