I mainly want to get what is if client flush for 10 times , then the server 
side dataRead method should be invoked 10 times, but I think it can't come 
true. I have followed peter's idea, but it can't resolve the problem. 

When I don't use NIO just use Socket then it can work well. I think the reason 
is what in socket way the thread was be blocked by in.readLine() method, if 
client have a flush, then the server can read the data:

    while (true)
    {
     String str = in.readLine();
     System.out.println(str);
     System.out.println("-----------------");
    }

but in SocketChannel and selector way ,the selector only check if channel have 
data coming. When data come then it will we invoke channel reading the data, 
but in the period of this process, maybe another flush have be invoked, then 
another ' Hello World ' have comed. So the dataRead moethod may print the 
combined string. Is this right ?  How should I do if I want to get what I want 
?   Thank you . 


hpq852
2006-07-24



发件人: Maarten Bosteels
发送时间: 2006-07-24 16:12:18
收件人: [email protected]
抄送: 
主题: Re: About Mina Question, Could you help me ?

I  do  not  quite  understand  the  problem.  Do  you  want  every  "Hello  
World"  to  be
in  a  separate  TCP  packet  ?
I  don't  think  it  is  a  good  idea  to  try  to  accomplish  that  behavior.
Your  code  should  not  depend  on  the  number  of  packets  used  to  
transfer  the
data.

Why  don't  you  use  delimiter  to  tell  the  messages  apart  ?
Our  use  TextLineDecoder:

http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/filter/codec/textline/TextLineDecoder.html

btw,  any  particular  reason  you  are  still  using  MINA  0.8  ?

Maarten

On  7/24/06,  peter  royal   <[EMAIL PROTECTED] >  wrote:
>
>  On  Jul  23,  2006,  at  11:14  AM,  hpq852  wrote:
>   >  It  alse  can't  work  well,  Now  the  client  is  :
>   >
>   >          public  void  run()
>   >          {
>   >            for(int  i=0;  i <10;  i++)
>   >            {
>   >              out.print("  Hello  World  \n");
>   >              out.flush();
>   >            }
>   >          }
>   >
>   >  if  I  invode  the  flush  method  for  10  times,  I  also  want  to  
> get  the
>   >  dataRead(IoSession  session,  ByteBuffer  rb)  mothed  invoked
>
>  Try  toggling  TCP_NODELAY.  By  default,  your  TCP  stack  will  try  to
>  combine  data  into  a  single  packet,  which  would  result  in  fewer
>  invocations  of  dataRead.
>
>  -epte
>
>
>  --
>  [EMAIL PROTECTED]  -  http://fotap.org/~osi
>
>
>
>
>
>

Reply via email to