Why am I getting this SocketException in my C# ser

2019-01-15 19:28发布

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.

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: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full

标签: c# sockets
2条回答
你好瞎i
2楼-- · 2019-01-15 20:10

I would also strongly suggest you look at your write thread, and how you are referencing resources related to the Socket. Ie, are you calling Close/Dispose for any NetworkStream or other objects you are using with the Socket? A code sample from the write thread would be helpful if you're still struggling with the problem.

You might also want to monitor the process memory and handle usage through the task manager.

查看更多
Fickle 薄情
3楼-- · 2019-01-15 20:12

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.

查看更多
登录 后发表回答