while (1)
{
if ((iThreadIndex+1) <= MAX_CONNET_NUMBER)
{
Clientfd[iThreadIndex] = accept(Listenfd,(struct sockaddr *&saClient,&saLenClient);
if (INVALID_SOCKET == Clientfd[iThreadIndex])
{
printf("accept error ,ERROR CODE:%d\n",WSAGetLastError());
return -1;
}
printf("connect from: IP-%s PORT-%d Now Connect Num:%d\n",inet_ntoa(saClient.sin_addr),saClient.sin_port,iThreadIndex+1); if (! _beginthreadex(NULL,0,acceptThread,(void *)&Listenfd,0,&ClientThread[iThreadIndex]))
{
printf("create accept thread faild\n");
goto FAILED;
}
else
{
iThreadIndex++;
}
}
else
{
printf("Maximum number of connections\n");
//Clientfd[iThreadIndex] = accept(Listenfd,(struct sockaddr *)&saClient,&saLenClient);
Sleep(200);
}
}
程序到达最大连接数时ACCETP还是成功、我想要当达到最大连接数时,客户端不能成功连接服务器。同时不能影响服务器对之前的连接的处理、上面代码可行,就是老打印 到达最大连接数我想让程序到达最大连接树。ACCEPT就失败?怎么弄?各位有什么好的办法解决最大连接数的问题?
解决方案 »
- Ontimer函数在CDialogBar类中不能响应
- 偶是新人!偶学习windows核心编程所遇到的问题!关于入口点函数!
- 如何在Dockbar绘制广告条
- MultiByteToWideChar 字符转换问题
- GDI+和GDI坐标系统改变导致长度不一致问题
- Notification Property 与 Get/Set Property的区别是什么?
- 看看这个问题怎么办
- 我正在看<深入浅出MFC>,但跳过了第三章<六大技术仿真>。有看法吗????
- 那位哥哥姐姐知道去哪儿下载x86 sdk for wince,国内的?
- 为什么我一调用beginthread 就告诉我出错 代码是从MSDN上抄下来的
- windows下,客户端如何创建一个长连接?
- 求助,帧差法
关闭之前的SOCKET 不会出问题吗、?、大家遇到这种问题咋办的?
if (INVALID_SOCKET == Clientfd[iThreadIndex])
{
printf("accept error ,ERROR CODE:%d\n",WSAGetLastError());
return -1;
}
//^^^^^^^
else
{
printf("Maximum number of connections\n");
//Clientfd[iThreadIndex] = accept(Listenfd,(struct sockaddr *)&saClient,&saLenClient);
Sleep(200);
}
//所以只要不是连接失败,就会提示 Maximum number of connectionsLZ注意if else 的关系,是else 与同它最近的if相对应(从中间开始向两边看)。
while (1)
{
if ((iThreadIndex+1) <= MAX_CONNET_NUMBER)
{
Clientfd[iThreadIndex] = accept(Listenfd,(struct sockaddr *)&saClient,&saLenClient);
if (INVALID_SOCKET == Clientfd[iThreadIndex])
{
printf("accept error ,ERROR CODE:%d\n",WSAGetLastError());
return -1;
}
printf("connect from: IP-%s PORT-%d Now Connect Num:%d\n",inet_ntoa(saClient.sin_addr),saClient.sin_port,iThreadIndex+1); if (! _beginthreadex(NULL,0,acceptThread,(void *)&Listenfd,0,&ClientThread[iThreadIndex]))
{
printf("create accept thread faild\n");
goto FAILED;
}
else
{
iThreadIndex++;
}
}
else
{
printf("Maximum number of connections\n");
//Clientfd[iThreadIndex] = accept(Listenfd,(struct sockaddr *)&saClient,&saLenClient);
Sleep(200);
}
}
求指教
Maximum length of the queue of pending connections. If set to SOMAXCONN, the underlying service provider responsible for socket s will set the backlog to a maximum reasonable value. There is no standard provision to obtain the actual backlog value.
是能监听到的最大数吧
其中还要做个管理socket线程的链表 及时清理废掉的线程