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

falconair shahbazc at gmail.com
Sun Jan 24 23:59:03 EST 2010


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
-- 
View this message in context: http://n2.nabble.com/Simple-local-server-doesn-t-seem-to-get-data-sent-by-local-client-tp4452226p4452226.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list