为什么我在我的 C# 服务中收到这个 SocketException? [英] Why am I getting this SocketException in my C# service?

查看:29
本文介绍了为什么我在我的 C# 服务中收到这个 SocketException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务负责从服务器读取和写入.读取和写入在不同的线程中完成.

I have a service that is responsible for reading and writing from a server. The reading and writing is done in different threads.

读取线程一直处于活动状态,而写入线程仅激活发送消息,并在消息写入服务器并收到响应后死亡.

The reader thread is active all the time whereas write thread only activates to send message and dies once message is written to server and response is received.

该服务运行了 4 天,之后我不断收到此错误,每当该服务尝试从端口读取时:

The service runs for 4 days and after that I am getting this error continuously, whenever the service tries to read from the port:

System.Net.Sockets.SocketException:无法对套接字执行操作,因为系统缺乏足够的缓冲空间或因为队列已满

System.Net.Sockets.SocketException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full

推荐答案

当您非常快速地建立大量传出连接并耗尽本地端口时,可能会发生这种情况.您可以在此处阅读有关临时端口范围"的信息.

This can happen when you establish a large number of outgoing connections very quickly and run out of local ports. You can read about the "ephemeral port range" here.

或者,您可能只是因为套接字用完了.确保在使用完毕后关闭它们.

Or, you may simply be running out of sockets. Make sure you close them after you are done using them.

这篇关于为什么我在我的 C# 服务中收到这个 SocketException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆