Custom Command line Protocol

Apr 13, 2013 at 6:07 PM
Hello, i would like to use your Command Line implementation, but i don't get it to work for my needs! Hopefully you could help me.

My Packets look as following

[[Size(Int16)][Key(Byte)]] [Body(Byte())]

and this is my Recievefilter im currently using
Class MyReceiveFilter
    Inherits FixedHeaderReceiveFilter(Of BinaryRequestInfo)
    Public Sub New()
    End Sub

    Protected Overrides Function GetBodyLengthFromHeader(header As Byte(), offset As Integer, length As Integer) As Integer
        Return CInt(header(offset)) + CInt(header(offset + 1)) - 3
    End Function

    Protected Overrides Function ResolveRequestInfo(header As ArraySegment(Of Byte), bodyBuffer As Byte(), offset As Integer, length As Integer) As BinaryRequestInfo
        Return New BinaryRequestInfo("ID" & header.Array(header.Offset + 2), bodyBuffer.CloneRange(offset, length))
    End Function
End Class
and i would like to use the Command Line implementation as following:
Public Class ID1
    Inherits CommandBase(Of AppSession, BinaryRequestInfo)
    Public Overrides Sub ExecuteCommand(session As AppSession, requestInfo As BinaryRequestInfo)

    End Sub
End Class
but i just can't get it work...

Any tips? i appreciate any help you can provide.
Apr 13, 2013 at 6:15 PM
Because you use BinaryRequestInfo, so you cannot use AppSession (only for StringRequestInfo) directly.

You can follow the GPSSocketServer sample project in the QuickStart of SuperSocket.
Apr 13, 2013 at 6:36 PM
Got i working! Removing the handler for 'NewRequestReceived' did the trick... shame on me!

Thanks, for this nice work!
Apr 13, 2013 at 8:37 PM
Edited Apr 14, 2013 at 12:18 AM
One problem i still have, my packets are encrypted with a dynamic key for each session. I need to decrypt the packet before it gets filtered for executing, because the HeaderKey is encrypted aswell!

Probaly here:
protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header, byte[] bodyBuffer, int offset, int length)
    // dynamic key stored in session
    byte DecryptKey = 0;
    return new BinaryRequestInfo(Enum.GetName(typeof(HeaderIn), Crypt.DecryptByte(header.Array[header.Offset + 2], DecryptKey)), Crypt.DecryptBytes(bodyBuffer.CloneRange(offset, length), DecryptKey));
Any Idea how to resolve the dynamic Decryptkey out of the Session? This is my last problem and i would love you if you could help me!

Edit: Just ported the Key to 'MyReceiveFilter', works as it should!

Thanks for this awesome work! You are great!
Apr 14, 2013 at 4:00 AM
Implement this interface IReceiveFilterInitializer for your receive filter, and then get session from the method of this interface.