Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新建多个tcpclient发送消息丢包问题 #24

Closed
sjd3211888 opened this issue Dec 30, 2019 · 2 comments
Closed

新建多个tcpclient发送消息丢包问题 #24

sjd3211888 opened this issue Dec 30, 2019 · 2 comments

Comments

@sjd3211888
Copy link

我新建了个一些tcpclient 向这个demo的tcpehcosession 发送消息,然后服务器在将消息返回,但是我发现每次收到的消息都少,通过网卡抓包 消息是回到了client的 不知道什么原因没上来,另外 这个时候我control+c tcpehcosession,这面客户端收感觉丢的消息这个时候就都上来了,请帮我看看

附上client的代码 tcpechosession 就负责回消息,啥都不干

int main() {
// 设置日志系统
Logger::Instance().add(std::make_shared());
Logger::Instance().add(std::make_shared());
Logger::Instance().setWriter(std::make_shared());
for (int i = 0; i < 200; i++)
{
TestClient::Ptr client(new TestClient());//必须使用智能指针
client->startConnect("192.168.1.189", 40996);//连接服务器
testmap.emplace(i, client);
}
sleep(30);
for (auto it = testmap.begin(); it != testmap.end(); it++)
{
it->second->send("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
}

@sjd3211888 sjd3211888 changed the title 新建多个tcpclient发送消息丢白问题 新建多个tcpclient发送消息丢包问题 Dec 30, 2019
@sjd3211888
Copy link
Author

Windows 环境 #define FD_SETSIZE 1024 多加了这句话 现在勉强能到1000个tcpclient了并且不丢包

@xia-chu
Copy link
Member

xia-chu commented Jan 2, 2020

windows下用的select ,每个select实例最多支持1024个fd。
如果你在windows下,这个1000个客户端都分配到一个select线程实例了,那么可能会存在添加select监听失败,会有以下警告:

attachEvent failed

具体代码为:
https://github.com/xiongziliang/ZLToolKit/blob/master/src/Network/Socket.cpp#L527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants