Custom Binary Protocol (no body length definition)

Jul 10, 2013 at 1:13 AM
Hello,
I've just started few days ago with this excellent framework and seems very good for all ascii based protocols, it's really flawless for all tests which I tried.

But now I have some problems with the binary form protocols.

Currently I'm stuck with one protocol where the length of the body is not defined (with example where the body length is defined, there is no problems which is great :) ).

I can only determine message by the 4bytes header and then parse it according to the predefined structure (I can not change the structure because it's predefined and there is no chance for modifications that length can be sent).

So, as I wrote, I only know the 4 bytes header, eg. 0xAABBCCDD, or 0xDDCCBBAA, etc...
And according to the header I can decide how the packet can be parsed (eg. by definition in documentation)

What do you recommend for this kind kind of custom protocol?

I've tried with "FixedHeaderReceiveFilter", but I'm stuck because currently I don't see the way how can I retrieve whole buffer and parse the content according to the "decrypted" header.

Any suggestions?

so example would be:
(4-bytes header)(10-bytes value1)(2-bytes value2)(6-bytes value3)(N-bytes value4)(5-bytes value5)

Thanks a lot for assistance!

Best Regards
Jul 10, 2013 at 2:48 AM
Please tell me how do you know the N according the 4 bytes header in your request format:

(4-bytes header)(10-bytes value1)(2-bytes value2)(6-bytes value3)(N-bytes value4)(5-bytes value5)
Jul 10, 2013 at 6:16 AM
Manny thanks for fast response :)

This is some kind a strange format...

The definition of the formatting is based on the header (there can be only few cases):
eg.
a)
(4-bytes header) == 0xAABBCCDD --> this tells me that this is the "a" type of message
(10-bytes value1) --> some encrypted value
(2-bytes value2) --> some encrypted value
(6-bytes value3) --> first two bytes tells me if there is the following next "N" segment; other 4-bytes some encrypted value
(N-bytes value4) --> previous segment tells me if this segment exists; if exists then first two bytes tells me how many (N) bytes is contained in this "N" segment
(5-bytes value5) --> the last encrypted value

b)
(4-bytes header) == 0xDDCCBBAA --> this tells me that this is the "b" type of message
(2-bytes value1) --> some encrypted value
(20-bytes value2) --> some encrypted value
(2-bytes value3) --> some encrypted value
(1-byte value4) --> some encrypted value
(1-byte value5) --> some encrypted value
(4-bytes value6) --> first two bytes tells me if there is the following next "N" segment; other 4-bytes some encrypted value
(N-bytes value7) --> previous segment tells me if this segment exists; if exists then first two bytes tells me how many (N) bytes is contained in this "N" segment
(5-bytes value8) --> the last encrypted value

c)
(4-bytes header) == 0xBB0000AA --> this tells me that this is the "c" type of message
(10-bytes value1) --> some encrypted value
(6-bytes value2) --> first two bytes tells me if there is the following next "N" segment; other 4-bytes some encrypted value
(N-bytes value3) --> previous segment tells me if this segment exists; if exists then first two bytes tells me how many (N) bytes is contained in this "N" segment
(5-bytes value4) --> the last encrypted value

d)
(4-bytes header) == 0xCC010102 --> this tells me that this is the "d" type of message
(10-bytes value1) --> some encrypted value
(2-bytes value2) --> some encrypted value
(5-bytes value3) --> the last encrypted value

So, as you can see, I know only the header, and based on the header I can assume how the message would look like.
That's the reason why I wrote that I have to parse the packet (calculate the length) based on the header.

This is the most complicated packet which I have to deal with because I have only "start delimiter" where I have to seek for the header and extract the rest.

Thanks in advance
Jul 12, 2013 at 1:11 AM
Edited Jul 12, 2013 at 1:11 AM
Currently I didn't implement the "plugin" for supersocket, but I've have solution how to get it.

I have a list of known headers, so I would iterate through them over received packet to locate the positions of the headers.
Then when I have positions, I would sort them and then I can grab the packages (length of each packet is position to position), then I can evaluate all packages.

Currently I have working "dirty" code on plain socket, but when I would have time I will try to implement it with supersocket.