Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I wrote code for controlling a robot which communicated using ethernet. everything is working fine but after a while (about 6-7hours) it looses communication probably due to buffer memory or something getting full and it throws following error-Unable to read data from the transport connection: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.

So how do I increase buffer memory or how do I get it empty regularly so connection always stays active. I'm using below code for streaming data-

_tcpClient = New System.Net.Sockets.TcpClient()
_tcpClient.Connect("", 10001)
_tcpStream = _tcpClient.GetStream()
_tcpStream.BeginRead(_readBuffer, 0, 256, New AsyncCallback(AddressOf OnDataAvailable), Nothing)

Thanks in advance, any help much appreciated.

What I have tried:

I was thinking to increase read buffer size from 256 to 1024 and see if it works but haven't got it done yet.

_tcpStream.BeginRead(_readBuffer, 0, 1024, New AsyncCallback(AddressOf OnDataAvailable), Nothing)
Updated 18-Nov-20 7:46am

1 solution

You add error handling / reporting before "fixing" it.

You need to know more about the situation that causes a problem. Then when the problem occurs, dump stats like "byte counts", etc.

In a "mission critical" situation you write monitors for recording reads, writes, timeouts.

You're asking if you should just throw code at it. No.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900