Echo example explaination

J. Mi jmi258 at gmail.com
Tue Sep 1 00:26:57 EDT 2009


Hi Christian,

Thanks! I got it. They echo each other just like "wild ping-pong". I like
that.

Cheers,
Jason

On Mon, Aug 31, 2009 at 8:24 AM, Christian Migowski <chrismfwrd at gmail.com>wrote:

> Hi Jason,
>
> i'll try to comment the example, hope it helps:
>
> 1. in EchoClient.java line 63 an instance of EchoHandler.java
> firstMessage is initialized with numbers because the 2nd constructor
> is used
> 2. in EchoServer.java an instance of EchoHandler.java firstMessage is
> initialized as empty (i.e. no data) because the 1st constructor is
> used
> 3. in EchoClient.java line 67 the client connects to the server, when
> this is done, channelConnected() method of EchoHandler is invoked in
> both the client and the server, but with different processing:
> 3a) EchoHandler.channelConnected of EchoClient will send firstMessage
> that is initialized with numbers
> 3b)  EchoHandler.channelConnected of EchoServer will not send anything
> because firstMessage is empty (there is nothing to send, even IF write
> is called)
> 4. Echohandler.messageReceived of EchoServer is invoked because it
> received the message from the client, in this method the data received
> is echoed back to the client
> 5. now Echohandler.messageReceived of EchoClient is doing the same as
> the one of EchoServer in 4.) and the wild ping-pong begins until you
> terminate the program
>
> hope this helps,
> greetings,
> christian!
>
>
> On Sat, Aug 29, 2009 at 12:54 AM, J. Mi<jmi258 at gmail.com> wrote:
> > Hi Trustin or any other experienced Netty user,
> >
> > I've downloaded Netty 3.1.2. GA and am currently trying to learn it via
> your
> > example of Echo. But I'm having a hard time understanding the example. I
> > started the server first and seeing a bunch of "0.000 MiB/s" output to
> the
> > console.
> >
> > I then started the client with the same port (as hard-coded in the
> server)
> > of 8080. I then see the output to the console as a bunch "0.0nn MiB/s"
> where
> > nn can be any number.
> >
> > I understand that the outout is from the thread ThroughputMonitor.
> >
> > I'm not sure if I understand the scenario how things work between the
> client
> > and the server.
> > The brief description from EchoClient.java is "Sends one message when a
> > connection is open and echoes back any received data to the server."
> > The brief description from EchoServer.java is "Echoes back any received
> data
> > from a client."
> > The EchoHandler.java has the method below:
> >
> > public void channelConnected (ChannelHandlerContext ctx,
> ChannelStateEvent
> > e) {
> >
> > // Send the first message. Server will not send anything here
> >
> > // because the firstMessage's capacity is 0.
> >
> > e.getChannel().write(
> >
> > firstMessage);
> >
> > }
> >
> > So between the client and the server, who sends a message and who echoes
> the
> > message?
> > When I added System.out
> > .println("Message from channelConnected: " + firstMessage.toString()); in
> > the method, I can see
> >
> > Message from channelConnected: BigEndianHeapChannelBuffer(ridx=0, widx=0,
> > cap=0)
> >
> > once when starting EchoClient.
> >
> > Could you please explain it to me? This example is a fundamental one. It
> > should be good starting point for me to understand Netty's NIO framework.
> >
> > If there is a forum some where about this topic and where I should post
> any
> > question like this, please advice as well.
> >
> > Thanks in advance
> > Jason
> > _______________________________________________
> > netty-dev mailing list
> > netty-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-dev
> >
> >
>
> _______________________________________________
> netty-dev mailing list
> netty-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-dev/attachments/20090831/bdf85efd/attachment.html 


More information about the netty-dev mailing list