Hello

So, im working with Mina 2.0.0.1 on Windows 7 with Java 1.6.0_18 , i have 
create my own ecoder and decoder, im receving only bytes.So what i do is i get 
the IoBuffer and read the first byte (get()), than i switch over the value and 
know witch packet is coming, than i use IoBuffer getShort and getInt. After 
that i push the received packet in a ThreadPool.now i can recive the next one, 
i do that on both Server and Client! i send a packet so, i put the first byte 
than the following values! Example: the packet with the key byte 1 has the 
follwing values: 2 int and a short! what i do is put the key byte with 
IoBuffer.put(1) and than 2x IoBuffer.putInt(100) and than 
IoBuffer.putShort(20). now the next packet!! on the Reveiving side i do 
IoBuffer.get() than 2x IoBuffer.getInt() and than IoBuffer.getShort(). that 
happens 100 times in a seconde or more! my problem is now that i receive that 
not in a correct order, same times there are packetes that i do not know,
 i thing that happens because thr a more than one thread how i jump over the 
receiving part. Maybe you can Help me!I Hoppe you can understand me English!

Code:
CumulativeProtocolDecoder

protected boolean doDecode(IoSession session, IoBuffer buffer, 
ProtocolDecoderOutput out) throws Exception {
        int firstByte = buffer.getInt();

        ReceivablePacket packet = switchPacket(firstByte, session);

        boolean received = packet != null;

        if (received) {
            //Geting the following Values!
            packet.receive(buffer);
            threadPool.executePacket(packet);
            out.write(packet);
        } else{
            System.out.println("Packet: " + 
PacketFactory.getPacketName(firstByte));                    
        }
        
        return received;
    }

//  Siwtch Block for finding the Packet
    protected abstract ReceivablePacket switchPacket(int firstByte, IoSession 
session);

ProtocolEncoderAdapter:
public void encode(IoSession session, Object message, ProtocolEncoderOutput 
out) throws Exception {
        SendablePacket packet = (SendablePacket) message;
        int length = packet.getSize();
        IoBuffer buffer = IoBuffer.allocate(length + 4);

        buffer.putInt((int)packet.getPacketID());
        packet.send(buffer);

        buffer.flip();
        out.write(buffer);
    }

Thank you 
________________________________

Reply via email to