1

According to the SuperSocket documentation, I have to implement ReceiveFilter which will receive binary data and convert it to object so my application can work with it.

Currently I'm working with the client side using SuperSocket.ClientEngine. From the documentation seems like the FixedHeaderReceiveFilter - Fixed Header with Body Length Protocol will work best for me. However I'm not quite understanding it's logic.

So it uses the first four bytes as the request name, and two bytes as the request body length.

/// +-------+---+-------------------------------+
/// |request| l |                               |
/// | name  | e |    request body               |
/// |  (4)  | n |                               |
/// |       |(2)|                               |
/// +-------+---+-------------------------------+

protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
{
    return (int)header[offset + 4] * 256 + (int)header[offset + 5];
}

protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header, byte[] bodyBuffer, int offset, int length)
{
    return new BinaryRequestInfo(Encoding.UTF8.GetString(header.Array, header.Offset, 4), bodyBuffer.CloneRange(offset, length));
}
  1. Why two bytes and how much it can contain? Why we taking the the fifth byte and multiplying it by 256? and then adding the sixth byte?
  2. So that means that server should assemble packet according to the protocol. How do I calculate the length of body and put it to the header?

My application is basically sends the xml request to the server and retrieves xml response. But want to be able to transfer big files over the network. Please help me.

Red Profit
  • 11
  • 2

0 Answers0