FW: Fwd: The results of your email commands

Cherbin Yaron Yaron.Cherbin at comverse.com
Wed Nov 26 06:14:04 EST 2008


 
 hi,

Ok I try to send subsciption again

About the echo client
I see that you create handler
  EchoHandler handler = new EchoHandler(firstMessageSize);  add it to
last

 and  connect to the server
When you first connect
channelConnected invoke and you don't send message because the
firstMessage's capacity is 0.
But if I want to send second message so I need to connect again to the
server?
  bootstrap.connect(new InetSocketAddress(host, port)); I don't
understood how do I send anther messgae after I connected to the server
Do I need to connect each time?
Please help me yaron

public class EchoClient {

    public static void main(String[] args) throws Exception {
        // Print usage if no argument is specified.
        if (args.length < 2 || args.length > 3) {
            System.err.println(
                    "Usage: " + EchoClient.class.getSimpleName() +
                    " <host> <port> [<first message size>]");
            return;
        }

        // Parse options.
        String host = args[0];
        int port = Integer.parseInt(args[1]);
        int firstMessageSize;

        if (args.length == 3) {
            firstMessageSize = Integer.parseInt(args[2]);
        } else {
            firstMessageSize = 256;
        }

        // Configure the client.
        ChannelFactory factory =
            new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());

        ClientBootstrap bootstrap = new ClientBootstrap(factory);
        EchoHandler handler = new EchoHandler(firstMessageSize);

        bootstrap.getPipeline().addLast("handler", handler);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("keepAlive", true);

        // Start the connection attempt.
        bootstrap.connect(new InetSocketAddress(host, port));

        // Start performance monitor.
        new ThroughputMonitor(handler).start();
    }
}
public class EchoHandler extends SimpleChannelHandler {

    private static final Logger logger = Logger.getLogger(
            EchoHandler.class.getName());

    private final ChannelBuffer firstMessage;
    private final AtomicLong transferredBytes = new AtomicLong();

    /**
     * Creates a server-side handler.
     */
    public EchoHandler() {
        firstMessage = ChannelBuffers.EMPTY_BUFFER;
    }

    /**
     * Creates a client-side handler.
     */
    public EchoHandler(int firstMessageSize) {
        if (firstMessageSize <= 0) {
            throw new IllegalArgumentException(
                    "firstMessageSize: " + firstMessageSize);
        }
        firstMessage = ChannelBuffers.buffer(firstMessageSize);
        for (int i = 0; i < firstMessage.capacity(); i ++) {
            firstMessage.writeByte((byte) i);
        }
    }

    public long getTransferredBytes() {
        return transferredBytes.get();
    }

    @Override
    public void handleUpstream(
            ChannelHandlerContext ctx, ChannelEvent e) throws Exception
{
        if (e instanceof ChannelStateEvent) {
            logger.info(e.toString());
        }

        // Let SimpleChannelHandler call actual event handler methods
below.
        super.handleUpstream(ctx, e);
    }

    @Override
    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);
    }

    @Override
    public void messageReceived(
            ChannelHandlerContext ctx, MessageEvent e) {
        // Send back the received message to the remote peer.
        transferredBytes.addAndGet(((ChannelBuffer)
e.getMessage()).readableBytes());
        e.getChannel().write(e.getMessage());
    }

    @Override
    public void exceptionCaught(
            ChannelHandlerContext ctx, ExceptionEvent e) {
        // Close the connection when an exception is raised.
        logger.log(
                Level.WARNING,
                "Unexpected exception from downstream.",
                e.getCause());
        e.getChannel().close();
    }
}

Yaron Cherbin
Software Engineer
R&D Core Converged Messaging
Comverse
Office: +972 3 6452032
Mobile: +972 52 8542332
yaron.cherbin at comverse.com
www.comverse.com

-----Original Message-----
From: Trustin Lee [mailto:trustin at gmail.com] On Behalf Of Trustin Lee
Sent: Wednesday, November 26, 2008 1:17 PM
To: Cherbin Yaron
Subject: Re: Fwd: The results of your email commands

What happens if you send a message to netty-dev at lists.jboss.org?

BTW You should send your questions to netty-users at lists.jboss.org (of
course assuming that you are subscribed to the netty-users list)

On Wed, Nov 26, 2008 at 08:07:14PM +0900, Cherbin Yaron wrote:
>  
> Le hi,
> I subscribe again and get this email
> yaron
> 
> Yaron Cherbin
> Software Engineer
> R&D Core Converged Messaging
> Comverse
> Office: +972 3 6452032
> Mobile: +972 52 8542332
> yaron.cherbin at comverse.com
> www.comverse.com
> 
> -----Original Message-----
> From: netty-dev-bounces at lists.jboss.org 
> [mailto:netty-dev-bounces at lists.jboss.org]
> Sent: Wednesday, November 26, 2008 1:08 PM
> To: Cherbin Yaron
> Subject: The results of your email commands
> 
> The results of your email command are provided below. Attached is your

> original message.
> 
> - Results:
>     You are already subscribed!
> 
> - Done.
> 

> From: Cherbin Yaron <Yaron.Cherbin at comverse.com>
> Subject: 
> To: netty-dev-request at lists.jboss.org
> Date: Wed, 26 Nov 2008 13:08:10 +0200
> 
> subscribe ddvu4vww


--
Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
--
what we call human nature in actuality is human habit
--
http://gleamynode.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ATT00112.dat
Type: application/pgp-signature
Size: 204 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20081126/a9c97281/attachment.bin 


More information about the netty-users mailing list