Two socket connection

paolom paolo8417 at hotmail.com
Mon Jun 27 04:59:09 EDT 2011


Hi, 

I need to have two socket connection to one host.

This is my code:

private void initSocket()
{
  	NioClientSocketChannelFactory sf = new NioClientSocketChannelFactory(
        Executors.newCachedThreadPool(),
        Executors.newCachedThreadPool()); 
  		
  		
        ClientBootstrap client1 = new ClientBootstrap(sf);
        ClientBootstrap client2 = new ClientBootstrap(sf);
        
        // Set up the pipeline factory.
        AHClientPipelineFactory clientFactory = new
AHClientPipelineFactory();

        client1.setPipelineFactory(clientFactory);
        client2.setPipelineFactory(clientFactory);
       
        
        client1.setOption("tcpNoDelay", true);
        client2.setOption("tcpNoDelay", true);
        
        client1.setOption("keepAlive", true);
        client2.setOption("keepAlive", true); 

}

private class AHClientPipelineFactory implements ChannelPipelineFactory {
	  
	public ChannelPipeline getPipeline() throws Exception {

	          ChannelPipeline pipeline = pipeline();

	          pipeline.addLast("stringDecoder", new
StringDecoder(CharsetUtil.US_ASCII));

	          pipeline.addLast("stringEncoder", new
stringEncoder(CharsetUtil.US_ASCII));          

                   pipeline.addLast("handler", new AysncSocketHandler());     

	  
	          return pipeline;
	      }
	}


where the AysncSocketHandler extends SimpleChannelUpstreamHandler.

The problem is that when I try to connect client2, after the client1 has
connected, I don't receive anything. I think it depends by
newCachedThreadPool() that reuses the client1 channel. I've tryed with the
same code with the newFixedThreadPool(2) but the result is the same.

Which is my fault?

Many thanks,

Paolo

--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Two-socket-connection-tp6519653p6519653.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list