hi John
As I know,the first condition is that
you should know when will be the character and when will be the binary data because the sequence of the thing should match the reading data. Of course, I am not sure the programme may contain some technique to do or may be needed to use some specific API to help you to do this.
I am also waiting for somebody who can give you some hints