You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Magarshak, Roman" <RM...@nds.com> on 2007/09/10 13:31:52 UTC

Write called not within mina handlers problem.

Hi All,
   I have the following problem:
When connection established I add a IoSession object to different
object, which some times needs to send a message to all connected
sockets.
The thing is that when I use IoSession.write(ByteBuffer) it is being
logged but not sent. 
Do I use Mina wrong?
 
Thank you in advance,
Roman
 
*********************************************************************************************************
This e-mail is confidential, the property of NDS Ltd and intended for the addressee only.  Any dissemination, copying or distribution of this message or any attachments by anyone other than the intended recipient is strictly prohibited.  If you have received this message in error, please immediately notify the postmaster@nds.com and destroy the original message.  Messages sent to and from NDS may be monitored.  NDS cannot guarantee any message delivery method is secure or error-free.  Information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.  We do not accept responsibility for any errors or omissions in this message and/or attachment that arise as a result of transmission.  You should carry out your own virus checks before opening any attachment.  Any views or opinions presented are solely those of the author and do not necessarily represent those of NDS.

NDS Limited Registered office: One Heathrow Boulevard, 286 Bath Road, West Drayton, Middlesex, UB7 0DQ, United Kingdom. A company registered in England and Wales  Registered no. 3080780   VAT no. GB 603 8808 40-00

To protect the environment please do not print this e-mail unless necessary.
**********************************************************************************************************


Re: Write called not within mina handlers problem.

Posted by mat <fo...@gmail.com>.
ByteBuffer.flip();
IoSession.write(ByteBuffer);


On 9/10/07, Magarshak, Roman <RM...@nds.com> wrote:
>
> Hi All,
>   I have the following problem:
> When connection established I add a IoSession object to different
> object, which some times needs to send a message to all connected
> sockets.
> The thing is that when I use IoSession.write(ByteBuffer) it is being
> logged but not sent.
> Do I use Mina wrong?
>
> Thank you in advance,
> Roman
>
>
> *********************************************************************************************************
> This e-mail is confidential, the property of NDS Ltd and intended for the
> addressee only.  Any dissemination, copying or distribution of this message
> or any attachments by anyone other than the intended recipient is strictly
> prohibited.  If you have received this message in error, please immediately
> notify the postmaster@nds.com and destroy the original message.  Messages
> sent to and from NDS may be monitored.  NDS cannot guarantee any message
> delivery method is secure or error-free.  Information could be intercepted,
> corrupted, lost, destroyed, arrive late or incomplete, or contain
> viruses.  We do not accept responsibility for any errors or omissions in
> this message and/or attachment that arise as a result of transmission.  You
> should carry out your own virus checks before opening any attachment.  Any
> views or opinions presented are solely those of the author and do not
> necessarily represent those of NDS.
>
> NDS Limited Registered office: One Heathrow Boulevard, 286 Bath Road, West
> Drayton, Middlesex, UB7 0DQ, United Kingdom. A company registered in England
> and Wales  Registered no. 3080780   VAT no. GB 603 8808 40-00
>
> To protect the environment please do not print this e-mail unless
> necessary.
>
> **********************************************************************************************************
>
>

Re: Write called not within mina handlers problem.

Posted by Trustin Lee <tr...@gmail.com>.
On 9/10/07, Magarshak, Roman <RM...@nds.com> wrote:
> Hi All,
>    I have the following problem:
> When connection established I add a IoSession object to different
> object, which some times needs to send a message to all connected
> sockets.
> The thing is that when I use IoSession.write(ByteBuffer) it is being
> logged but not sent.
> Do I use Mina wrong?

Are you using the same ByteBuffer instance to broadcast a message?
Then it can be a problem because ByteBuffer position will be changed
per each write.  The solution is to create duplicate buffers.  It
performs well because it doesn't copy the content of the buffer but
the position and the limit value:

ByteBuffer message = ...;;
Collection<IoSession> sessions = ...;
for (IoSession s: sessions) {
    s.write(message.duplicate());
}

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6