Netty client
Murali Mohan Rath
mmrath at gmail.com
Mon Jun 21 19:43:16 EDT 2010
Thanks again.
I had a look at the examples and tried to write the code for POC purpose.
But I am getting exception a after the second response. Not sure what is
happening. It would be great if someone can point me what I am doing wrong.
<code>
public static void main(String arg[]) {
String host = "localhost";
int port = 5003;
ChannelFactory factory =
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ClientPipelineFactory pipelineFactory = new ClientPipelineFactory();
ClientBootstrap bootstrap = new ClientBootstrap(factory);
bootstrap.setPipelineFactory(pipelineFactory);
bootstrap.setOption("keepAlive", true);
bootstrap.connect(new InetSocketAddress(host, port));
logger.info("Attempting connection");
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
port));
// Wait until the connection is closed or the connection attempt
fails.
future.getChannel().getCloseFuture().awaitUninterruptibly();
logger.info("Connection closed");
// Shut down thread pools to exit.
bootstrap.releaseExternalResources();
}
</code>
Application Logs looks as below:
09:38:53.838 [main] INFO MessageHandler - [id: 0x0134a7d8] OPEN
09:38:53.932 [main] INFO Application - Attempting connection
09:38:53.932 [main] INFO MessageHandler - [id: 0x01c695a6] OPEN
09:38:53.932 [New I/O client worker #1-1] INFO MessageHandler - [id:
0x0134a7d8, /127.0.0.1:4619 => localhost/127.0.0.1:5003] BOUND:
/127.0.0.1:4619
09:38:53.932 [New I/O client worker #1-1] INFO MessageHandler - [id:
0x0134a7d8, /127.0.0.1:4619 => localhost/127.0.0.1:5003] CONNECTED:
localhost/127.0.0.1:5003
09:38:54.026 [New I/O client worker #1-1] DEBUG MessageHandler - Sending
message [<message>]
09:38:54.026 [New I/O client worker #1-1] DEBUG MessageHandler - Message
sent [<message>]
09:38:54.151 [New I/O client worker #1-1] DEBUG MessageHandler - Received
message [BigEndianHeapChannelBuffer(ridx=0, widx=154, cap=1024)]
09:38:54.151 [New I/O client worker #1-1] DEBUG MessageHandler - Received
message [<response>]
09:38:54.916 [main] INFO Application - Connection closed
09:38:54.916 [New I/O client boss #1] INFO MessageHandler - [id:
0x01c695a6] CLOSED
09:38:54.963 [New I/O client boss #1] WARN MessageHandler - Unexpected
exception from downstream.
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) [na:1.5.0_06]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:525)
[na:1.5.0_06]
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:374)
[netty-3.1.5.GA.jar:na]
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:344)
[netty-3.1.5.GA.jar:na]
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:266)
[netty-3.1.5.GA.jar:na]
at
org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)
[netty-3.1.5.GA.jar:na]
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
[na:1.5.0_06]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
[na:1.5.0_06]
at java.lang.Thread.run(Thread.java:595) [na:1.5.0_06]
09:38:55.010 [New I/O client worker #1-1] INFO MessageHandler - [id:
0x0134a7d8, /127.0.0.1:4619 => localhost/127.0.0.1:5003] DISCONNECTED
09:38:55.010 [New I/O client worker #1-1] INFO MessageHandler - [id:
0x0134a7d8, /127.0.0.1:4619 => localhost/127.0.0.1:5003] UNBOUND
09:38:55.010 [New I/O client worker #1-1] INFO MessageHandler - [id:
0x0134a7d8, /127.0.0.1:4619 => localhost/127.0.0.1:5003] CLOSED
http://netty-forums-and-mailing-lists.685743.n2.nabble.com/file/n5206747/ClientPipelineFactory.java
ClientPipelineFactory.java
http://netty-forums-and-mailing-lists.685743.n2.nabble.com/file/n5206747/MessageHandler.java
MessageHandler.java
--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Netty-client-tp5193745p5206747.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list