You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Björn Haverland <bj...@world-of-services.de> on 2012/01/28 23:35:30 UTC

Protocolcodecfiltertutorial

Hi @all,

i?m new to mina so a big hello to all of you ;)

So i have also a question. I?m searching for a more detailed 
protocollcodecfilter tutorial.  The one which is online is good for 
starting, but what do i have to do if i have more telegrams then one in 
each direction? I have some startbytes which indicates me which kind of 
telegramm will follow. Could anybody give me a hint how i could solve this?

Thank you!!

Best regards

Björn

Re: Protocolcodecfiltertutorial

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 1/29/12 7:15 PM, Bjoern Haverland wrote:
> Am 29.01.2012 01:18, schrieb Emmanuel Lecharny:
>> On 1/29/12 12:49 AM, Bjoern Haverland wrote:
>>> Am 29.01.2012 00:10, schrieb Emmanuel Lecharny:
>>>> On 1/28/12 11:35 PM, Björn Haverland wrote:
>>>>> Hi @all,
>>>>>
>>>>> i?m new to mina so a big hello to all of you ;)
>>>>>
>>>>> So i have also a question. I?m searching for a more detailed 
>>>>> protocollcodecfilter tutorial.  The one which is online is good 
>>>>> for starting, but what do i have to do if i have more telegrams 
>>>>> then one in each direction? I have some startbytes which indicates 
>>>>> me which kind of telegramm will follow. Could anybody give me a 
>>>>> hint how i could solve this?
>>>>
>>>> Do you mean that you have a first byte in your message that defines 
>>>> the message's type ?
>>>
>>> Yepp (2 Bytes)
>> So it should not be a problem. Depending on those two bytes, you will 
>> decode the following bytes knowing what they will be transformed to.
>>
>> There are two important things to understand :
>> 1) the bytes you are receiving *may* contain more than one message 
>> (once decoded)
>> 2) the bytes you are receiving *may* not be enough to decode a full 
>> message (this is due to the possible fragmentation on TCP)
>>
>> Once you understand that, decoding the bytes is pretty easy.
>>
>> To deal with (1), you have to loop on the bytes until you can't 
>> decode any more message
>> To deal with (2) is a bit more complex : you have to know the size of 
>> the bytes needed to create a full message, or the bytes must have a 
>> terminator (a special byte or set of bytes that close the message).
>>
>> In any case, you can use the CumulativeProtocolDecoder to deal with 
>> those two scenarii.
>>
>>
>> Again, the Image decoder exaple given on the web site is probably the 
>> page to read.
>>>
>>>
> Hi Emmanuel,
>
> thanks for your tips. I already mentioned them. But where is struggle 
> with, is the point, how and when do i differentiate the telegrams.
>
> The point is, every telegram starts with these 2 bytes and ends with 2 
> bytes. The protocol is very rudimentary, it will always come just one 
> telegram until the other side has confirmed the receiving. So do i 
> have more then one protocolcodecfilter, one for every telegram or do i 
> have one protocolcodecfilter where i have to wait for the bytes and 
> then first read out the first 2 bytes to check which telegram was sent 
> and then build my objects with the rest of the telegram.
Obviously, the second solution is clearly easier. Just be sure to use 
the CumulativeProtocolDecoder to get all the bytes up to the closing 2 
bytes. make those two bytes a signal for the decoding start.
>
> I´m just struggling how to use mina with more then one kind of 
> telegram in each direction. In the tutorial was the incoming data 
> casted to the object, because there was only this one telegram which 
> represents this one kind of object. But what do i have to do if i have 
> more telegrams with more kinds of objects.

You will know which Object to create as soon as you have read the two 
first bytes. Even if you have tens of different types of 'telegrams', 
once you have decoded the two bytes, it will be easy to do something like :

short type = in.readShort();

switch ( type ) {
   case TEL_TYPE_1 : // decode a telegram type 1
   case TEL_TYPE_2 : // decode a telegram type 2
...
}


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: Protocolcodecfiltertutorial

Posted by Bjoern Haverland <mr...@arcor.de>.
Am 29.01.2012 01:18, schrieb Emmanuel Lecharny:
> On 1/29/12 12:49 AM, Bjoern Haverland wrote:
>> Am 29.01.2012 00:10, schrieb Emmanuel Lecharny:
>>> On 1/28/12 11:35 PM, Björn Haverland wrote:
>>>> Hi @all,
>>>>
>>>> i?m new to mina so a big hello to all of you ;)
>>>>
>>>> So i have also a question. I?m searching for a more detailed 
>>>> protocollcodecfilter tutorial.  The one which is online is good for 
>>>> starting, but what do i have to do if i have more telegrams then 
>>>> one in each direction? I have some startbytes which indicates me 
>>>> which kind of telegramm will follow. Could anybody give me a hint 
>>>> how i could solve this?
>>>
>>> Do you mean that you have a first byte in your message that defines 
>>> the message's type ?
>>
>> Yepp (2 Bytes)
> So it should not be a problem. Depending on those two bytes, you will 
> decode the following bytes knowing what they will be transformed to.
>
> There are two important things to understand :
> 1) the bytes you are receiving *may* contain more than one message 
> (once decoded)
> 2) the bytes you are receiving *may* not be enough to decode a full 
> message (this is due to the possible fragmentation on TCP)
>
> Once you understand that, decoding the bytes is pretty easy.
>
> To deal with (1), you have to loop on the bytes until you can't decode 
> any more message
> To deal with (2) is a bit more complex : you have to know the size of 
> the bytes needed to create a full message, or the bytes must have a 
> terminator (a special byte or set of bytes that close the message).
>
> In any case, you can use the CumulativeProtocolDecoder to deal with 
> those two scenarii.
>
>
> Again, the Image decoder exaple given on the web site is probably the 
> page to read.
>>
>>
Hi Emmanuel,

thanks for your tips. I already mentioned them. But where is struggle 
with, is the point, how and when do i differentiate the telegrams.

The point is, every telegram starts with these 2 bytes and ends with 2 
bytes. The protocol is very rudimentary, it will always come just one 
telegram until the other side has confirmed the receiving. So do i have 
more then one protocolcodecfilter, one for every telegram or do i have 
one protocolcodecfilter where i have to wait for the bytes and then 
first read out the first 2 bytes to check which telegram was sent and 
then build my objects with the rest of the telegram.

I´m just struggling how to use mina with more then one kind of telegram 
in each direction. In the tutorial was the incoming data casted to the 
object, because there was only this one telegram which represents this 
one kind of object. But what do i have to do if i have more telegrams 
with more kinds of objects.
Is there may be a tutorial available, which extends the Image decoder 
tutorial?

Thank you very much

Björn
>
>


Re: Protocolcodecfiltertutorial

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 1/29/12 12:49 AM, Bjoern Haverland wrote:
> Am 29.01.2012 00:10, schrieb Emmanuel Lecharny:
>> On 1/28/12 11:35 PM, Björn Haverland wrote:
>>> Hi @all,
>>>
>>> i?m new to mina so a big hello to all of you ;)
>>>
>>> So i have also a question. I?m searching for a more detailed 
>>> protocollcodecfilter tutorial.  The one which is online is good for 
>>> starting, but what do i have to do if i have more telegrams then one 
>>> in each direction? I have some startbytes which indicates me which 
>>> kind of telegramm will follow. Could anybody give me a hint how i 
>>> could solve this?
>>
>> Do you mean that you have a first byte in your message that defines 
>> the message's type ?
>
> Yepp (2 Bytes)
So it should not be a problem. Depending on those two bytes, you will 
decode the following bytes knowing what they will be transformed to.

There are two important things to understand :
1) the bytes you are receiving *may* contain more than one message (once 
decoded)
2) the bytes you are receiving *may* not be enough to decode a full 
message (this is due to the possible fragmentation on TCP)

Once you understand that, decoding the bytes is pretty easy.

To deal with (1), you have to loop on the bytes until you can't decode 
any more message
To deal with (2) is a bit more complex : you have to know the size of 
the bytes needed to create a full message, or the bytes must have a 
terminator (a special byte or set of bytes that close the message).

In any case, you can use the CumulativeProtocolDecoder to deal with 
those two scenarii.


Again, the Image decoder exaple given on the web site is probably the 
page to read.
>
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Re: Protocolcodecfiltertutorial

Posted by Bjoern Haverland <mr...@arcor.de>.
Am 29.01.2012 00:10, schrieb Emmanuel Lecharny:
> On 1/28/12 11:35 PM, Björn Haverland wrote:
>> Hi @all,
>>
>> i?m new to mina so a big hello to all of you ;)
>>
>> So i have also a question. I?m searching for a more detailed 
>> protocollcodecfilter tutorial.  The one which is online is good for 
>> starting, but what do i have to do if i have more telegrams then one 
>> in each direction? I have some startbytes which indicates me which 
>> kind of telegramm will follow. Could anybody give me a hint how i 
>> could solve this?
>
> Do you mean that you have a first byte in your message that defines 
> the message's type ?

Yepp (2 Bytes)


Re: Protocolcodecfiltertutorial

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 1/28/12 11:35 PM, Björn Haverland wrote:
> Hi @all,
>
> i?m new to mina so a big hello to all of you ;)
>
> So i have also a question. I?m searching for a more detailed 
> protocollcodecfilter tutorial.  The one which is online is good for 
> starting, but what do i have to do if i have more telegrams then one 
> in each direction? I have some startbytes which indicates me which 
> kind of telegramm will follow. Could anybody give me a hint how i 
> could solve this?

Do you mean that you have a first byte in your message that defines the 
message's type ?


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com