You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by tan wenlong <ta...@yahoo.com> on 2006/11/14 03:28:49 UTC

Problem of SocketConnector

Hi,When I use the SocketConnector send messages to Server, Sometime It will send several messages as one message. For example, I hope that SocketConnector send "abc" and "def", but SocketConnector send "abcdef". Is it a bug of mina?
 		
---------------------------------
 Mp3疯狂搜-新歌热歌高速下   

Re: Problem of SocketConnector

Posted by Trustin Lee <tr...@gmail.com>.
On 11/15/06, Cameron Taggart <ca...@gmail.com> wrote:
>
> Added to FAQ.
>
> http://cwiki.apache.org/confluence/display/MINA/FAQ#FAQ-WhydoesSocketConnectorsendseveralmessagesasonemessage%3F


Looks great!

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: Problem of SocketConnector

Posted by Cameron Taggart <ca...@gmail.com>.
Added to FAQ.
http://cwiki.apache.org/confluence/display/MINA/FAQ#FAQ-WhydoesSocketConnectorsendseveralmessagesasonemessage%3F

cheers,
Cameron

On 11/14/06, Trustin Lee <tr...@gmail.com> wrote:
> We'd better add this answer to our FAQ page.  IIRC, we got this same
> question more than ten times. :D
>
> Trustin
>
> On 11/14/06, Niklas Therning <ni...@trillian.se> wrote:
> >
> > tan wenlong wrote:
> > > Hi,When I use the SocketConnector send messages to Server, Sometime It
> > will send several messages as one message. For example, I hope that
> > SocketConnector send "abc" and "def", but SocketConnector send "abcdef". Is
> > it a bug of mina?
> > >
> > >
> > No, this is due to your OS trying to send packets more efficiently (see
> > http://en.wikipedia.org/wiki/Nagle_algorithm). You can enable/disable
> > Nagle's algorithm by a call to SocketSessionConfig.setTcpNoDelay(), e.g.:
> >
> > ((SocketSessionConfig) connector.getSessionConfig()).setTcpNoDelay(false)
> >
> > However, even if you do this you cannot expect one session.write(bytes)
> > in MINA to correspond to one TCP packet on your network. You should
> > probably implement your own MINA ProtocolDecoder to handle the assembly
> > of incoming bytes into message objects. The TextLineCodec is a good
> > start if the protocol you're implementing is based on text lines. For a
> > more advanced example have a look at the SumUp example in the MINA
> > distribution.
> >
> > HTH
> >
> > --
> > Niklas Therning
> > www.spamdrain.net
> >
> >
>
>
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

Re: Problem of SocketConnector

Posted by Trustin Lee <tr...@gmail.com>.
We'd better add this answer to our FAQ page.  IIRC, we got this same
question more than ten times. :D

Trustin

On 11/14/06, Niklas Therning <ni...@trillian.se> wrote:
>
> tan wenlong wrote:
> > Hi,When I use the SocketConnector send messages to Server, Sometime It
> will send several messages as one message. For example, I hope that
> SocketConnector send "abc" and "def", but SocketConnector send "abcdef". Is
> it a bug of mina?
> >
> >
> No, this is due to your OS trying to send packets more efficiently (see
> http://en.wikipedia.org/wiki/Nagle_algorithm). You can enable/disable
> Nagle's algorithm by a call to SocketSessionConfig.setTcpNoDelay(), e.g.:
>
> ((SocketSessionConfig) connector.getSessionConfig()).setTcpNoDelay(false)
>
> However, even if you do this you cannot expect one session.write(bytes)
> in MINA to correspond to one TCP packet on your network. You should
> probably implement your own MINA ProtocolDecoder to handle the assembly
> of incoming bytes into message objects. The TextLineCodec is a good
> start if the protocol you're implementing is based on text lines. For a
> more advanced example have a look at the SumUp example in the MINA
> distribution.
>
> HTH
>
> --
> Niklas Therning
> www.spamdrain.net
>
>


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: Problem of SocketConnector

Posted by Niklas Therning <ni...@trillian.se>.
tan wenlong wrote:
> Hi,When I use the SocketConnector send messages to Server, Sometime It will send several messages as one message. For example, I hope that SocketConnector send "abc" and "def", but SocketConnector send "abcdef". Is it a bug of mina?
>  		
>   
No, this is due to your OS trying to send packets more efficiently (see
http://en.wikipedia.org/wiki/Nagle_algorithm). You can enable/disable
Nagle's algorithm by a call to SocketSessionConfig.setTcpNoDelay(), e.g.:

((SocketSessionConfig) connector.getSessionConfig()).setTcpNoDelay(false)

However, even if you do this you cannot expect one session.write(bytes)
in MINA to correspond to one TCP packet on your network. You should
probably implement your own MINA ProtocolDecoder to handle the assembly
of incoming bytes into message objects. The TextLineCodec is a good
start if the protocol you're implementing is based on text lines. For a
more advanced example have a look at the SumUp example in the MINA
distribution.

HTH

-- 
Niklas Therning
www.spamdrain.net


答复: Problem of SocketConnector

Posted by 凌晨 <li...@usertunnel.com>.
Dear tang
It's Not A MINA's Bug. It's a behavior of TCP/IP .So you should look into
the Sumup example. You should make your server receive expected packages by
your own logic

-----邮件原件-----
发件人: tan wenlong [mailto:tanvstan@yahoo.com] 
发送时间: 2006年11月14日 10:29
收件人: mina-dev@directory.apache.org
主题: Problem of SocketConnector

Hi,When I use the SocketConnector send messages to Server, Sometime It will
send several messages as one message. For example, I hope that
SocketConnector send "abc" and "def", but SocketConnector send "abcdef". Is
it a bug of mina?
 		
---------------------------------
 Mp3疯狂搜-新歌热歌高速下