Erratic message reception when more than 1 client

"Trustin Lee (이희승)" trustin at gmail.com
Wed Jan 13 23:21:06 EST 2010


I updated the whole documentation and examples so that beginners do not
make this mistake often.  Stay tuned for the next release! :)

Sergey S wrote:
> Hi
> 
> it looks like you are using same pipeline for all channels, it's wrong way
> for a pipeline with encoders/decoders. You should use PipelineFactory like
> in Telnet example:
> 
> 32  public class TelnetServer {
> 33  
> 34      public static void main(String[] args) throws Exception {
> 35          // Configure the server.
> 36          ServerBootstrap bootstrap = new ServerBootstrap(
> 37                  new NioServerSocketChannelFactory(
> 38                          Executors.newCachedThreadPool(),
> 39                          Executors.newCachedThreadPool()));
> 40  
> 41          TelnetServerHandler handler = new TelnetServerHandler();
> 42          bootstrap.setPipelineFactory(new
> TelnetPipelineFactory(handler));
> 43  
> 44          // Bind and start to accept incoming connections.
> 45          bootstrap.bind(new InetSocketAddress(8080));
> 46      }
> 47  }
> 
> 
> 
> 
> wiradikusuma wrote:
>> Hi guys,
>>
>> I'm experiencing erratic message reception when there are more than one
>> client connected to my Netty-based TCP server.
>>
>> The client is a dummy MINA client sending 1KB XML string 5000 times:
>> -- client ----------------------------------------------
>> for 1 to 5000 { session.write(something) }
>> --------------------------------------------------------
>>
>> The server looks like this:
>> -- Spring ----------------------------------------------
>> <bean id="executor" class="...ThreadPoolTaskExecutor" scope="prototype">
>> 	<property name="corePoolSize" value="10"/>
>> 	<property name="maxPoolSize" value="5000"/>
>> </bean>
>> --------------------------------------------------------
>>
>> -- connection initiation -------------------------------
>> ChannelFactory cf = new OioServerSocketChannelFactory(executor, executor);
>> ServerBootstrap bootstrap = new ServerBootstrap(cf);
>>
>> ChannelPipeline pipeline = bootstrap.getPipeline();
>> pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
>> Delimiters.lineDelimiter()));
>> pipeline.addLast("decoder", new StringDecoder());
>> pipeline.addLast("encoder", new StringEncoder());
>> pipeline.addLast("handler", clientHandler);
>>
>> bootstrap.setOption("child.tcpNoDelay", true);
>> bootstrap.setOption("child.keepAlive", true);
>> bootstrap.setOption("reuseAddress", true);
>> bootstrap.bind(new InetSocketAddress(serverPort));
>> --------------------------------------------------------
>>
>> -- handler ---------------------------------------------
>> @ChannelPipelineCoverage("all")
>> class ClientHandler extends SimpleChannelHandler {
>> channelConnected(...) {
>> 	ctx.setAttachment(new ClientXml());
>> }
>>
>> messageReceived(...) {
>> 	Channel channel = event.getChannel();
>> 	ClientXml data = (ClientXml) context.getAttachment();
>> 	data.addXmlPart((String) event.getMessage());
>>
>> 	final String xml = data.getNextXML();
>> 	if (xml != null) {
>> 		executor.execute(new Runnable() {
>> 		public void run() {
>> 			// do something useful
>> 		}
>> 		}
>> 	}
>> }
>> --------------------------------------------------------
>>
>> When only one client connected to the server, everything is OK. 
>> All messages received correctly, all XMLs logged correctly. 
>> But when there are more than one, my log starts to look like this:
>>
>> --------------------------------------------------------
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
>> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
>> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
>> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
>> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
>> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
>> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
>> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
>> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> <?xml version='1.0'
>> encoding='UTF-8' standalone='yes'?> <?xml version='1.0' encoding='UTF-8'
>> standalone='yes'?> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
>> <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <?xml
>> version='1.0' encoding='UTF-8' standalone='yes'?> ... continue until
>> unlimited
>> --------------------------------------------------------
>>
>> Any idea what happens and what should I do?
>>
> 

-- 
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/20100114/9962ce26/attachment.bin 


More information about the netty-users mailing list