Server and Client at the same time

"이희승 (Trustin Lee)" trustin at gmail.com
Thu Jun 18 17:28:55 EDT 2009


On 2009-06-19 오전 3:57, gonzalo diethelm wrote:
> Hi Trustin,
> 
> Thanks very much for your new Proxy example. I had taken some time
> yesterday to try and write what I was describing before (using the
> Telnet example as a basis); it will be very useful to me to compare it
> to what you wrote. I have several questions (and metaquestions) for now:
> 
> ·         It would be great if the Java source code (like the link you
> provided) could be shown with syntax coloring and line numbers.

Try this one instead then:

http://fisheye.jboss.org/browse/Netty/trunk/src/main/java/org/jboss/netty/example/proxy

or I would just check out Netty and load it up in your IDE. :)

> ·         In your HexDumpProxy example, you only create a
> ServerBootstrap but do not create a ClientBootstrap; instead, you create
> the NioClientSocketChannelFactory “stand alone”. Then, within the
> HexDumpProxyInboundHandler you do create the ClientBootstrap. Why do you
> do it this way?

It is because the ChannelHandler for the outbound connection is
determined only after the inbound connection is accepted.
OutboundHandler needs a reference to the Channel of the inbound connection.

> ·         In the HexDumpProxyPipelineFactory you only add one handler (a
> HexDumpProxyInboundHandler) to the pipeline. Yesterday, with my own
> code, I tried doing this but got runtime exceptions indicating I could
> not cast a String to a ChannelBuffer. After looking more closely to the
> Telnet example, I decided to add three additional handlers before my
> own: a DelimiterBasedFrameDecoder, a StringDecoder and a StringEncoder.
> With that, my code worked fine, but I don't understand how you don't
> need those same handlers in the Proxy.

It's because the ChannelHandlers in the HexDumpProxy example are using
ChannelBuffer as its primary message type.  Please note the down-casts
to ChannelBuffer in the ChannelHandler's messageReceived() handler
methods.  In the telnet example, I down-cast to String.

> ·         From what I understand, the OutboundHandler as implemented is
> receiving messages and sending them right back to the proxy. This caters
> to my “requirements”, but it might be clearer for a simple proxy example
> to just print out the received messages.

It does.  Find 'System.out.println' in the source code.

> ·         Other than the javadoc documentation, is there a good “manual
> for developers using Netty” anywhere? The user guide is very
> enlightening, but I am thinking more along the lines of architectural
> designs, patterns, when to use a class or another, etc.

The documentation section of the web site is all we have.  You might
want to search the forum / mailing list archive.  Also, please check out
the wiki.  The user guide is not completed yet and I'm still thinking
about its full table of contents, so please feel free to give us feed
back; I do want to know what is missing and what needs more explanation.

> Finally, for full disclosure: I posted a similar question (I mean my
> “requirements”) on the MINA mailing list. I know next to nothing about
> MINA and Netty, and am trying to compare them for my purposes.

No problem.  Please let us know if you find something interesting. ;)

HTH,
Trustin

> Thanks again and best regards,
> 
>  
> 
> -- 
> 
> Gonzalo Diethelm
> 
> DCV - Chile
> 
>  
> 
>  
> 
>> -----Original Message-----
> 
>> From: netty-users-bounces at lists.jboss.org [mailto:netty-users-
> 
>> bounces at lists.jboss.org] On Behalf Of "??? (Trustin Lee)"
> 
>> Sent: Friday 12 Jun 2009 04:50
> 
>> To: netty-users at lists.jboss.org
> 
>> Subject: Re: Server and Client at the same time
> 
>>
> 
>> Hi Gonzus,
> 
>>
> 
>> I have been asked by many people about implementing such a proxy server,
> 
>> so I decided to write an example proxy server.  It's much easier to
> 
>> write an implementation than to explain how to do that, especially when
> 
>> it comes down to proxy server. :)
> 
>>
> 
>> Check this out:
> 
>>
> 
>> http://viewvc.jboss.org/cgi-
> 
>> bin/viewvc.cgi/netty/trunk/src/main/java/org/jboss/netty/example/proxy/
> 
>>
> 
>> Shutting down is not very different from writing an ordinary server or
> 
>> client application.  Only one difference is that you need to shut down
> 
>> both client side and server side ChannelFactory at last.
> 
>>
> 
>> HTH,
> 
>> Trustin
> 
>>
> 
>> On 2009-06-11 오후 11:56, gonzus wrote:
> 
>> >
> 
>> > Hello everyone, this is my first post here. I am examining Netty (after
> 
>> a
> 
>> > brief look at MINA) and would like to gather opinions on how to
> 
>> implement a
> 
>> > proof of concept for my requirements.
> 
>> >
> 
>> > I intend to have two copies of the same program running on the same
> 
>> machine
> 
>> > (this is not a requirement, it is just easier). The two programs will be
> 
>> run
> 
>> > like this:
> 
>> >
> 
>> > $ program 8001 8002
> 
>> > $ program 8002 8001
> 
>> >
> 
>> > This means the first copy will bind on port 8001 and try to connect to
> 
>> port
> 
>> > 8002, and the second program will bind on port 8002 and try to connect
> 
>> to
> 
>> > port 8001. After successful connection, the program will send a single
> 
>> > string "Hello World"; after making sure it has sent one string and
> 
>> received
> 
>> > one string, the program will shut down gracefully.
> 
>> >
> 
>> > What I am trying to learn is how to do the following in Netty:
> 
>> >
> 
>> > 1. Have an acceptor and connector at the same time running on the same
> 
>> > program.
> 
>> > 2. Handle failed connect attempts and a reconnection policy.
> 
>> > 3. Proper way of shutting down a server.
> 
>> >
> 
>> > Are there any examples that could help me implement this? Any
> 
>> suggestions?
> 
>> >
> 
>> > Extra credit :-D if the program ends up being capable of running a
> 
>> single
> 
>> > copy like this and doing "the obvious":
> 
>> >
> 
>> > $ program 8003 8003
> 
>> >
> 
>> > Thanks in advance and best regards.
> 
>>
> 
>>
> 
>> --
> 
>> — Trustin Lee, http://gleamynode.net/
> 
>  
> 
> ------------------------------------------------------------------------
> 
> Declaración de confidencialidad: Este Mensaje esta destinado para el uso
> de la o las personas o entidades a quien ha sido dirigido y puede
> contener información reservada y confidencial que no puede ser
> divulgada, difundida, ni aprovechada en forma alguna. El uso no
> autorizado de la información contenida en este correo podrá ser
> sancionado de conformidad con la ley chilena. Si usted ha recibido este
> correo electrónico por error, le pedimos eliminarlo junto con los
> archivos adjuntos y avisar inmediatamente al remitente, respondiendo
> este mensaje.
> 
> Disclosure: This Message is to be used by the individual, individuals or
> entities that it is addressed to and may include private and
> confidential information that may not be disclosed, made public nor used
> in any way at all. Unauthorized use of the information in this
> electronic mail message may be subject to the penalties set forth by
> Chilean law. If you have received this electronic mail message in error,
> we ask you to destroy the message and its attached file(s) and to
> immediately notify the sender by answering this message.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users


-- 
— Trustin Lee, http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20090619/3bad50a3/attachment.bin 


More information about the netty-users mailing list