Write on channel on channelConnected()

"Trustin Lee (이희승)" trustin at gmail.com
Wed Mar 24 01:47:14 EDT 2010


Hi Bruno,

Bruno Mello wrote:
> Hello all,
> 
> I think I found a bug on Netty 3.2.0 BETA1.
> 
> If I try to write on a channel inside the channelConnected method I get a
> "java.lang.IllegalArgumentException: unsupported message type" exception. 
> 
>    public void channelConnected(final ChannelHandlerContext ctx, final
> ChannelStateEvent e) {
>       ctx.getChannel().write("hello");
>    }

It's perhaps because you did not configure the pipeline properly.  If
you are building text line protocol, refer to the telnet example.

> Also, if I put a long routine in channelConnected if behaves in an
> unexpected fashion:
> 
> For instance, a client connects after pressing a button and when connected
> it displays a message "connected".
> 
> With the code bellow the message "connected" only shows up 5 seconds before
> pressing the button.
> 
>    public void channelConnected(final ChannelHandlerContext ctx, final
> ChannelStateEvent e) {
>        Thread.sleep(5000);
>    }
> 
>>From my understanding channelConnected should be called AFTER the channel is
> really connected and ready to exchange messages.

If channelConnected() is called, it means the connection has been
established.  However, during sleep(), no additional I/O will occur for
the connection because you did not return the control to Netty.  It's
like Swing.  It you sleep in an event listener, UI does not respond.

HTH,
Trustin
-- 
what we call human nature in actuality is human habit
http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100324/5b9b06af/attachment-0001.bin 


More information about the netty-users mailing list