Simple local server doesn't seem to get data sent by local client

"Trustin Lee (이희승)" trustin at gmail.com
Mon Jan 25 00:26:27 EST 2010


You have overridden handleUpstream and handleDownstream without calling
its super method.  It means messageReceived will not be called at all -
please take a look into the source code: http://is.gd/6YEyw

To fix the problem, call super.handleUpstream() or
super.handleDownstream() in your overridden method.

HTH,
Trustin

falconair wrote:
> I am trying to run a simple test with a DefaultLocalServerChannelFactory and
> DefaultLocalClientChannelFactory (version 3.2 ALPHA3).
> 
> I connect to the server, send some text and expect debug messages to display
> the client-outgoing message and server-incoming message.  It doesn't look
> like the server is receiving it, but the client doesn't complain.  Not sure
> what is going on here, some comments are in-line:
> 
> public void initiatorLocalBootstrap(){
> 	//Server
> 	ServerBootstrap server = new ServerBootstrap(new
> DefaultLocalServerChannelFactory());
> 	ChannelPipelineFactory serverPipeline = new ChannelPipelineFactory() {
> 
> 		@Override
> 		public ChannelPipeline getPipeline() throws Exception {
> 			ChannelPipeline pipe = org.jboss.netty.channel.Channels.pipeline();
> 			pipe.addLast("handler", new SimpleChannelHandler(){
> 
> 				@Override
> 				public void handleDownstream(ChannelHandlerContext arg0,ChannelEvent
> event) throws Exception {
> 					System.out.println("SERVER-DOWN:"+event);
> 				}
> 
> 				@Override
> 				public void handleUpstream(ChannelHandlerContext arg0,ChannelEvent
> event) throws Exception {
> 					System.out.println("SERVER-UP:"+event);
> 				}
> 
> 				@Override
> 				public void messageReceived(ChannelHandlerContext ctx,MessageEvent
> event) throws Exception {
> 					System.out.println("SERVER-msgRcvd:"+event);
> 				}});
> 
> 			return pipe;
> 		}
> 	};
> 	server.setPipelineFactory(serverPipeline);
> 	//Even if I comment out the following line, nothing changes!
> 	server.bind(new LocalAddress(1));
> 
> 
> 	//Client
> 	ClientBootstrap client = new ClientBootstrap(new
> DefaultLocalClientChannelFactory());
> 
> 			client.getPipeline().addLast("handler", new SimpleChannelHandler(){
> 
> 				@Override
> 				public void handleDownstream(ChannelHandlerContext arg0,ChannelEvent
> event) throws Exception {
> 					System.out.println("CLIENT-DOWN:"+event);
> 				}
> 
> 				@Override
> 				public void handleUpstream(ChannelHandlerContext arg0,ChannelEvent
> event) throws Exception {
> 					System.out.println("CLIENT-UP:"+event);
> 				}
> 
> 				@Override
> 				public void messageReceived(ChannelHandlerContext ctx,MessageEvent
> event) throws Exception {
> 					System.out.println("CLIENT-msgRcvd:"+event);
> 				}});
> 
> 	ChannelFuture cf = client.connect(new LocalAddress(1));
> 	//addListener doesn't seem to work, the call back is never called
> 	//perhaps client connects before the listener is setup?
> 	//I replaced it with awaitUn..., but this just seems to wait forever
> 	//cf.awaitUninterruptibly();
> 	try {
> 		Thread.sleep(3000);
> 	} catch (InterruptedException e) {
> 	}
> 	cf.getChannel().write("HELLOWORLD");
> 	//cf.getChannel().close().awaitUninterruptibly();
> 	System.out.println("FIN");
> 
> }
> 
> 
> 
> The following is printed on screen:
> <warnings about ChannelPipelineCoverage >
> CLIENT-UP:[id: 0x01b34126] OPEN
> CLIENT-DOWN:[id: 0x01b34126] CONNECT: local:1
> CLIENT-DOWN:[id: 0x01b34126] WRITE: HELLOWORLD
> FIN
> 
> I expect to see "SERVER-*" messages, but they never show.
> If the client doesn't actually connect to the server, then shouldn't the
> write fail with some sort of "not connected" error?
> 
> Thanks

-- 
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/20100125/25515acd/attachment.bin 


More information about the netty-users mailing list