jovaan
Posts: 18
Joined: Wed May 31, 2006 9:57 pm
Contact: Website

When is it necessary to use Stream.Flush()?

Thu Jul 06, 2006 1:02 am

Hi, I have experienced that Bluetools works much more reliably when I Flush() the stream as often as possibly - specially when there is packet of incoming data, then I send some data, again incoming data etc. It seems the data send can be delayed "forever" if the Flush() is not called, even if there is nothing incoming - but the stack is maybe waiting for data to come because I call instantly after writing some synchronous read method from Stream.

However it seems little bit harsh to call Flush() after every couple of send bytes. Are there any recommendations on which situations the Flush() must be called, like before synchronous read instantly after WriteByte etc?

Also, is there any performance improvement to be gained when calling Flush() also before/after read operations (for example to ensure the data would be available for reading ASAP)?

Andreas2
Posts: 108
Joined: Sun Feb 13, 2005 3:19 pm

RE: When is it necessary to use Stream.Flush()?

Thu Jul 06, 2006 12:23 pm

Hi,

The general contract of the "Flush" method is that the stream dumps its buffered data into an underlying stream. Thus, if you e.g. serialize a packet and write it byte for byte into the channel, each byte may be written into a buffer and thus not delivered to the peer until the data is flushed. This means that the stream needs to be flushed when the packet has been fully written.

So, to conclude: flush should be called when you wish the data to be delivered. The reason for buffering in the first place is to optimize performance.

Note that there's no buffering in the current version of bluetools.

Regards,
Andreas Nilsson
Franson Support

jovaan
Posts: 18
Joined: Wed May 31, 2006 9:57 pm
Contact: Website

RE: When is it necessary to use Stream.Flush()?

Thu Jul 06, 2006 5:06 pm

Hi Andreas, could you confirm that the current method ServiceStream.Flush() does nothing. This would be strange because I have noted different behaviour when calling Flush() after a write.

Andreas2
Posts: 108
Joined: Sun Feb 13, 2005 3:19 pm

RE: When is it necessary to use Stream.Flush()?

Thu Jul 06, 2006 5:17 pm

Hi,

The ServiceStream.Flush method does nothing. Older versions of bluetools use buffering in Franson.BlueTools.ServiceStream, but this was removed due to increased complexity.

So, possible reasons for the behaviour would be:
* You are not using the most recent version of BlueTools.
* You are using an intermediate buffered stream.

Just to clarify, the Flush method in bluetools is completely empty.

If you want buffering (which increases both performance and stability) you now need to use a System.IO.BufferedStream.

For further assistance, please post more information about the platforms and devices you use and some sample code.

Regards,
Andreas Nilsson
Franson Support

jovaan
Posts: 18
Joined: Wed May 31, 2006 9:57 pm
Contact: Website

RE: When is it necessary to use Stream.Flush()?

Mon Jul 10, 2006 3:30 pm

I have now updated the SW with latest beta release of Bluetools, and with that I don't see any changes in behaviour whether I use flush() or not. Thanks for clarification.

ravey72
Posts: 14
Joined: Wed Nov 30, 2005 11:49 pm
Location: United Kingdom

RE: When is it necessary to use Stream.Flush()?

Thu Jul 13, 2006 4:02 am

Hi,
I think you had a Post up regarding 'Cheap BT Dongles' not using Microsoft/Widcomm Stacks, and whether Bluetools would support the other stacks used by these cheap dongles. Did you get a response to this because i could no longer find your Post?

I have a similar situation and am also waiting for some clarification from Franson.

Thanks
Ravey

Return to “BlueTools”