Issue on Netty4: client cannot reconnect

207 views
Skip to first unread message

Frederic

unread,
Sep 10, 2012, 10:13:32 AM9/10/12
to ne...@googlegroups.com
Hi,

Since Github is for the moment ouf of line, I post here my concern on Netty 4.

I try to get into it, and of course, while I am trying to convert Netty3 based code to Netty4, I try also the examples and check some functionalities.
One of the first I saw with an issue was also noted on the https://netty.io/Documentation/New+and+Noteworthy page as one comment.

I take the Echo example, add in the server side a limit of "ping-ping" like this:

    public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) {
        limit --;
        if (limit > 0) {
            ByteBuf out = ctx.nextOutboundByteBuffer();
            out.discardReadBytes();
            out.writeBytes(in);
            ctx.flush();
        } else {
            // end
            ctx.close();
        }
    }

Then in the client, I added the following at the end of the run method:

            // Start the client. Original one
            ChannelFuture f = b.connect().sync();

            // Wait until the connection is closed.
            f.channel().closeFuture().sync();

            // and now try to reconnect NEW Code
            System.out.println("try to restart");
            // Start the client.
            f = b.connect().sync();

            // Wait until the connection is closed.
            f.channel().closeFuture().sync();

And I get the following output:

    sept. 10, 2012 4:06:03 PM io.netty.handler.logging.LoggingHandler
    Infos: [id: 0xfedfd297] REGISTERED
    sept. 10, 2012 4:06:03 PM io.netty.handler.logging.LoggingHandler
    Infos: [id: 0xfedfd297, /0.0.0.0:3780 => /127.0.0.1:8080] ACTIVE
    try to restart
    Exception in thread "main" sept. 10, 2012 4:06:03 PM io.netty.handler.logging.LoggingHandler
    Infos: [id: 0xfedfd297, /0.0.0.0:3780 :> /127.0.0.1:8080] INACTIVE
    java.lang.IllegalStateException: channel already registered: [id: 0xfedfd297, /0.0.0.0:3780 :> /127.0.0.1:8080]
        at io.netty.bootstrap.Bootstrap.init(Bootstrap.java:185)
        at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:162)
        at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:152)
        at io.netty.example.echo.EchoClient.run(EchoClient.java:73)
        at io.netty.example.echo.EchoClient.main(EchoClient.java:102)
    sept. 10, 2012 4:06:03 PM io.netty.handler.logging.LoggingHandler
    Infos: [id: 0xfedfd297, /0.0.0.0:3780 :> /127.0.0.1:8080] UNREGISTERED

Do I missed something in the logic?

I will come back later on with a "traffic" handler for Netty4 if I understand the first steps correctly...

Cheers,
Frederic

Frederic

unread,
Sep 10, 2012, 10:15:05 AM9/10/12
to ne...@googlegroups.com
Sorry, I just see that Github is back again, si ignore this one. I will put it in Github right now...

Cheers,
Reply all
Reply to author
Forward
0 new messages