Help me,io.netty.handler.codec.DecoderException!!!

279 views
Skip to first unread message

PengFei Du

unread,
Apr 9, 2014, 10:45:58 PM4/9/14
to jets...@googlegroups.com

Hello everyone

    I am a developer from China, a few days ago, I found Nadron and learned the example.
    so I want to simplify the Nadron lostdecade example for apply to other my games, but when I made another project, then run it,
    data can't transfer from client to server, and GameServer.log has some exceptions:
   
    2014-04-10 10:22:11,568 [GameRoomSession:339][TRACE]:Added Network handler to EventDispatcher of GameRoom org.mynamepfd.example.EchoGameRoom@4b5e33a7, for session: PlayerSession [id=DefaultSession2player=io.nadron.app.impl.DefaultPlayer@1f, parentGameRoom=org.mynamepfd.example.EchoGameRoom@4b5e33a7, protocol=null, isShuttingDown=false]
    2014-04-10 10:22:11,584 [DefaultToServerHandler:48][ERROR]:Exception during network communication: {}.
    io.netty.handler.codec.DecoderException: java.io.InvalidClassException: failed to read class descriptor
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:480)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
        at java.lang.Thread.run(Unknown Source)
   
    My EchoGameRoom.java 's code list below:
   
    public class EchoGameRoom extends GameRoomSession
    {

        protected EchoGameRoom(GameRoomSessionBuilder gameRoomSessionBuilder)
        {
            super(gameRoomSessionBuilder);
            addHandler(new RoomSessionHandler(this));
        }

        @Override
        public void onLogin(final PlayerSession playerSession)
        {
            System.out.println("Recive connection from client......");
            playerSession.addHandler(
                new DefaultSessionEventHandler(playerSession)
                {
                    @Override
                    protected void onDataIn(Event event)
                    {
                        System.out.println("Data flow from client to server......");
                        if(null != event.getSource())
                        {
                            event.setEventContext(new DefaultEventContext(playerSession, null));
                            playerSession.getGameRoom().send(event);
                        }
                    }
                }
            );
        }
       
        // ...
    }
   
     Console can't print Data flow from client to server......, Can you tell me why?Thanks.
    

abraham menacherry

unread,
Apr 9, 2014, 11:02:59 PM4/9/14
to jets...@googlegroups.com
Hi,

It looks like you may have misconfigured the game protocol. Could you also attach your SpringConfig file and show how the game room is being configured?



--
You received this message because you are subscribed to the Google Groups "jetserver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jetserver+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

PengFei Du

unread,
Apr 10, 2014, 12:42:49 AM4/10/14
to jets...@googlegroups.com
Hi Abraham, thanks for your reply!


As figure show, it's your project, I just add my EchoGameRoom.java in package
lostdecade, and make some changes about LDClient.java and SpringConfig.java.

// EchoGameRoom.java


public class EchoGameRoom extends GameRoomSession
{

    public EchoGameRoom(GameRoomSessionBuilder gameRoomSessionBuilder)
    {
        super(gameRoomSessionBuilder);
        addHandler(new EchoGameRoomSessionHandler(this));
    }

    @Override
    public void onLogin(final PlayerSession playerSession)
    {

        System.out.println("1...");


        playerSession.addHandler(
            new DefaultSessionEventHandler(playerSession)
            {
                @Override
                protected void onDataIn(Event event)
                {

                    System.out.println("2...");


                    if(null != event.getSource())
                    {
                        event.setEventContext(new DefaultEventContext(playerSession, null));
                        playerSession.getGameRoom().send(event);
                    }
                }
               
            }
        );
    }
   

    public static class EchoGameRoomSessionHandler extends SessionMessageHandler
    {
        public EchoGameRoomSessionHandler(GameRoomSession session)
        {
            super(session);
        }

        @Override
        public void onEvent(Event event)
        {
            System.out.println("3......");
        }
    }
}

//LDClient.java
LoginBuilder builder = new LoginBuilder().username("user")
        .password("pass").connectionKey("EchoGameRoom")
        .nadronTcpHostName("localhost").tcpPort(18090);
       
//SpringConfig.java
@Configuration
@ImportResource("classpath:/beans.xml")
public class SpringConfig
{
    @Autowired
    @Qualifier("nettyObjectProtocol")
    private Protocol nettyObjectProtocol;
   
    public Game EchoGame()
    {
        return new SimpleGame(3, "EchoGame");
    }
   
    public GameRoom EchoGameRoom()
    {
        GameRoomSessionBuilder gameRoomSessionBuilder =
            new GameRoomSessionBuilder();
        gameRoomSessionBuilder
            .parentGame(EchoGame())
            .gameRoomName("EchoGameRoom")
            .protocol(nettyObjectProtocol);
        return new EchoGameRoom(gameRoomSessionBuilder);
    }
   
    @Bean(name = "lookupService")
    public LookupService lookupService()
    {
        Map<String, GameRoom> Rooms = new HashMap<String, GameRoom>();
        Rooms.put("EchoGameRoom", EchoGameRoom());
       
        return new SimpleLookupService(Rooms);
    }
}
When I run GameServer.java first, then run LDClient, server's console print
1...
2...
3...
It's right!!!
When console print 1..., client login server, print 2..., client send some datas to server,
print 3..., event was transfer for EchoGameSessionHandler

But when I make my project, as figure below,

following above steps, server's console only print 1...,
GameServer.log contains below exceptions:

2014-04-10 11:18:56,801 [LoginHandler:63][DEBUG]:Login attempt from /127.0.0.1:3027
2014-04-10 11:18:56,817 [LoginHandler:200][TRACE]:Sending GAME_ROOM_JOIN_SUCCESS to channel [id: 0xaf72abe2, /127.0.0.1:3027 => /127.0.0.1:18090]
2014-04-10 11:18:56,817 [LoginHandler:242][TRACE]:Sending GAME_ROOM_JOIN_SUCCESS to channel [id: 0xaf72abe2, /127.0.0.1:3027 => /127.0.0.1:18090] completed
2014-04-10 11:18:56,817 [LoginHandler:245][TRACE]:Going to clear pipeline
2014-04-10 11:18:56,817 [GameRoomSession:180][TRACE]:Protocol to be applied is: io.nadron.protocols.impl.NettyObjectProtocol
2014-04-10 11:18:56,817 [NettyObjectProtocol:28][TRACE]:Going to apply NETTY_OBJECT_PROTOCOL on session: PlayerSession [id=DefaultSession2player=io.nadron.app.impl.DefaultPlayer@1f, parentGameRoom=org.mynamepfd.example.EchoGameRoom@4b5e33a7, protocol=null, isShuttingDown=false]
2014-04-10 11:18:56,817 [GameRoomSession:339][TRACE]:Added Network handler to EventDispatcher of GameRoom org.mynamepfd.example.EchoGameRoom@4b5e33a7, for session: PlayerSession [id=DefaultSession2player=io.nadron.app.impl.DefaultPlayer@1f, parentGameRoom=org.mynamepfd.example.EchoGameRoom@4b5e33a7, protocol=null, isShuttingDown=false]
2014-04-10 11:18:56,826 [DefaultToServerHandler:48][ERROR]:Exception during network communication: {}.


io.netty.handler.codec.DecoderException: java.io.InvalidClassException: failed to read class descriptor
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:480)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Unknown Source)

Caused by: java.io.InvalidClassException: failed to read class descriptor
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at io.netty.handler.codec.serialization.ObjectDecoder.decode(ObjectDecoder.java:73)
    at io.nadron.handlers.netty.EventObjectDecoder$SourceDecoder.decode(EventObjectDecoder.java:44)
    at io.nadron.handlers.netty.EventObjectDecoder.decode(EventObjectDecoder.java:28)
    at io.nadron.handlers.netty.EventObjectDecoder.decode(EventObjectDecoder.java:13)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: io.nadron.example.lostdecade.LDGameState
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at io.netty.handler.codec.serialization.ClassLoaderClassResolver.resolve(ClassLoaderClassResolver.java:31)
    at io.netty.handler.codec.serialization.CompactObjectInputStream.readClassDescriptor(CompactObjectInputStream.java:55)
    ... 22 more
   
Because my project can run, so I think my configure are right, but why server's console can't parse client's data?
Thanks.

在 2014年4月10日星期四UTC+8上午11时02分59秒,Abraham Menacherry写道:

PengFei Du

unread,
Apr 10, 2014, 12:44:23 AM4/10/14
to jets...@googlegroups.com
Sorry, it's my first time to use google bbs, send some repeated replys for you.T_T
在 2014年4月10日星期四UTC+8上午11时02分59秒,Abraham Menacherry写道:

abraham menacherry

unread,
Apr 10, 2014, 7:02:17 AM4/10/14
to jets...@googlegroups.com
Hi,

You are using "NettyObjectProtocol" but actually LDGameRoom is using web socket protocol. You can still use this nettyobjectprotocol, but then your client also needs to use the same protocol. Can you tell me what protocol you client is using?

Thanks,
Abraham

PengFei Du

unread,
Apr 12, 2014, 4:17:26 AM4/12/14
to jets...@googlegroups.com
Eh, thanks for your reply, as you say, I forgot add 

session.resetProtocol(NettyObjectProtocol.INSTANCE);

at begin of client session's StartEventHandler.

Thanks, Abraham.

Now, because I am an C# developer for Windows Phone Game use Cocos2d-x for XNA, 
so I want write a client that C# can use, your code is so long,
If I have some question, can you help me?

Sorry my poor english,Hah.
 
在 2014年4月10日星期四UTC+8下午7时02分17秒,Abraham Menacherry写道:

abraham menacherry

unread,
Apr 12, 2014, 8:25:04 AM4/12/14
to jets...@googlegroups.com
I am not an familiar with C# network programming. The way to write client is to choose one of the protocol's and implement it in c#. An easy one to do might be the websocket protocol since C# will have libraries for it. 
Reply all
Reply to author
Forward
0 new messages