Login  
Search All Forums
Dart Home | PowerTCP Telnet for .NET | Custom Development Reply | PowerTCP Telnet for .NET Topics | Forums   
AuthorForum: PowerTCP Telnet for .NET
Topic: DataAvailable returns true when no data available
rsagherian

From: Windsor, CT USA
Posts: 2
Member Since: 10/25/12
posted October 25, 2012 2:45 PM

If I attempt to use the DataAvailable property of the underlying network stream it will sometime return true when there is no data available. This causes the Read statement to throw an exception. I can catch the exception but the unnecessary Read attempt slows down the program since the code will wait for the read timeout to expire.

 While telnet1.NetworkStream.DataAvailable
   data = telnet1.Read(m_rcvBuf)
 End While

Any suggestions?
Thanks.
Nick B (Admin)

From: Utica, NY USA
Posts: 572
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted October 25, 2012 4:04 PM

Hello,

The base Microsoft NetworkStream encapsulates all of our network communication; the Telnet object consumes control data, which is not passed up to be read with Telnet.Read(). Data may be available on the socket, but not any data that would be passed up by Telnet.

Our 4.x model is designed specifically to get rid of the need to implement code like this. With its design, a Read may be always pending on a worker thread, allowing the UI/Main thread to continue unhindered by a blocking operation, and for new data to immediately become available to the application when it arrives (by calling Telnet.Marshal(data,,)).

I would recommend examining our included Telnet Client sample for a demonstration of the Start method (on which the specified Delegate function executes on), the Read() loop inside of TelnetModel.ReceiveData() which executes on the worker thread, and the use of the Marshal method (which marshals data to the UI/main thread from the worker thread, and raises the Telnet_Data event (when an object of type Data is supplied to the method)) at the end of the receive loop.

Additionally, with your use of data = telnet1.Read(m_rcvBuf) in a while loop, the data object will be replaced with the newly read data (if more data is availabe on the socket), so you might lose some data.

If this does not apply, can you describe more about the structure of your application, and what you're trying to do?
rsagherian

From: Windsor, CT USA
Posts: 2
Member Since: 10/25/12
posted October 26, 2012 8:45 AM

Nick, thanks for the quick response. Your explanation makes sense. I wrote my code that way because it just seemed to be simpler. Send a command and then wait for a response. I will try your suggestion and see how it goes.
Thanks again.
Reply | PowerTCP Telnet for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX