Android Question Advantages of AsyncStreams InitializePrefix over just Initialize AND buffer size

hatzisn

Expert
Licensed User
Longtime User
Good afternoon to all of you,

until now I was using asyncstreams with just "Initialize" because I had already implemented my own communications protocol, but I would like to know if there is any advantage (and which) of using InitializePrefix instead of using just initialize. My impression until now reading different messages in the forum, is that you still have to reassemble yourself the file/message sent in different fire-ups of "Async_Newdata" and the only advantage is that you know the length of the message in buffer (removing the first 4 bytes - which leaves us with 96 bytes of message in every buffer()). Is there any advantage on using initializeprefix instead of just initialize and a second question is can we upscale the buffer to more bytes somehow?

Thanks in advance
 
Solution
Two things, I think.


Yes - but in some situations knowing the length of the data message is a useful advantage and can make the data transfer more robust. It does mean, of course, that you have control of the sender to ensure that the prefix is present. But I guess less useful if your data size is always fixed.


I don't understand this - using InitializePrefix does not limit the usable record size. Mind you it is some time since I have used this mode, but I don't think that it has changed.

No, do not apoligize. I may very well be the one that is wrong since I have no experience with InitializePrefix but only Initialize. So far my understanding was that the prefix is send in every Async_NewData fire-up. The way you describe...

Brian Dean

Well-Known Member
Licensed User
Longtime User
Two things, I think.

the only advantage is that you know the length of the message in buffer
Yes - but in some situations knowing the length of the data message is a useful advantage and can make the data transfer more robust. It does mean, of course, that you have control of the sender to ensure that the prefix is present. But I guess less useful if your data size is always fixed.

(removing the first 4 bytes - which leaves us with 96 bytes of message in every buffer())
I don't understand this - using InitializePrefix does not limit the usable record size. Mind you it is some time since I have used this mode, but I don't think that it has changed.
 
Last edited:
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Two things, I think.


Yes - but in some situations knowing the length of the data message is a useful advantage and can make the data transfer more robust. It does mean, of course, that you have control of the sender to ensure that the prefix is present. But I guess less useful if your data size is always fixed.


I don't understand this - using InitializePrefix does not limit the usable record size. Mind you it is some time since I have used this mode, but I don't think that it has changed.

No, do not apoligize. I may very well be the one that is wrong since I have no experience with InitializePrefix but only Initialize. So far my understanding was that the prefix is send in every Async_NewData fire-up. The way you describe it makes me think that it is send, the prefix, only once in the beginning and then reconstructing the message/file in every Async_NewData fire-up you just count the bytes. Is this correct?
 
Upvote 0
Solution

Brian Dean

Well-Known Member
Licensed User
Longtime User
Both ends must initialise the connection in this mode. When a data array is sent the message length is added automatically as a prefix. At the receiving end the data ready event is raised only when the complete data string has been received. This simplifies message handling to some extent although I don't suppose that it really affects reliability.

Just to be clear - the messages can vary in length.
 
Last edited:
Upvote 0
Top