客户端无法使用 TCP 套接字重新连接到服务器
我的套接字连接有问题。
我有一个客户端和一个服务器应用程序,其中服务器应用程序侦听特定端口上的客户端。
500 个客户端已连接并将数据发送到服务器进行处理,一切正常。
在特定时间,我关闭了所有客户端,也关闭了服务器。当我在 10 分钟后重新启动服务器并在 2 分钟后重新启动客户端时,很少有客户端 (5-15) 能够重新连接。
请给我一个解决方案,为什么所有客户端都没有重新连接。
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
endpoint = new IPEndPoint(IPAddress.Any, int.Parse(txt_server_port.Text));
mainSocket.Bind(endpoint);
mainSocket.Listen(100);
mainSocket.BeginAccept(new AsyncCallback(ConnetedClient), mainSocket);
I have a problem with socket connection.
I have a Client and a Server application where the server application listens for clients on a particular port.
500 clients are connected and sending data to the server to be processed and everything is working fine.
At particular time, I closed all clients and also close the server. When I restart the server after 10 minutes and restart the clients 2 minutes later, very few clients (5-15) are able to reconnect.
Please give me a solution why all clients do not reconnect.
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
endpoint = new IPEndPoint(IPAddress.Any, int.Parse(txt_server_port.Text));
mainSocket.Bind(endpoint);
mainSocket.Listen(100);
mainSocket.BeginAccept(new AsyncCallback(ConnetedClient), mainSocket);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的所有客户端都尝试连接在一起,则可能是侦听器积压已满。
您可以增加传递给
Listen
方法的参数中的积压。If all your clients are trying to connect together it might be that the listener backlog got filled.
You can increase the backlog in the parameter passed to the
Listen
method.