You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Sergey Mamitko <sm...@isd.dp.ua> on 2008/06/26 19:37:20 UTC

MINA Clients and Servers

Hello,

What is REAL difference from communication point between MINA client (IoConnector) and server (IoAcceptor)
They are both can send and receive data.

Maybe question is what server don't know where data should be send. 
But in real situation, if server is smart and can send data when connection to it established, then IoConnect becomes server?

Example:

First component:
IoConnector connector = new SocketConnector();
<set of filters here>
ConnectFuture connectFuture = connector.connect(getRemoteSocketAddress(), new SomeIoHandler1());
connectFuture.join();

if (connectFuture.isConnected())
{
   SocketAddress socketAddress = connectFuture.getSession().getLocalAddress();
   IoAcceptor acceptor = new SocketAcceptor();
   IoAcceptorConfig acceptorConfig = new SocketAcceptorConfig();
   ((SocketAcceptorConfig) acceptorConfig).setReuseAddress(true);
   ((SocketAcceptorConfig) acceptorConfig).setDisconnectOnUnbind(false);
   <set of filters here>
    acceptor.bind(socketAddress, new SomeIoHandler2(), acceptorConfig);
}


Second component:

Usual server (but different from first component) with handler which will send data on opening session event:

class SomeIoHandler3 extends IoHandlerAdapter
{
   public void sessionOpened(IoSession session) throws Exception
   {
         WriteFuture writeFuture = session.write("<some data to send here>");
         writeFuture.join();
   }
}


And what happen with first component. Both handlers SomeIoHandler1 from client and SomeIoHandler2 from server will receive data.
So who is client and who is server?
And how I can to do correct handling of such processes?

The main idea is to use the same channel for first component.

MINA: 1.1.7
JDK: 1.5
OS: Win, Unix

Thank you in advance.
-------------------------
Sergey Mamit'ko 
ISD, http://www.isd.dp.ua/index.html.en

Re: MINA Clients and Servers

Posted by Sergey Mamitko <sm...@isd.dp.ua>.
Thank you for response

> Sergey Mamitko wrote:
>> Hello,
>>
>> What is REAL difference from communication point between MINA client 
>> (IoConnector) and server (IoAcceptor)
>> They are both can send and receive data.
>>
> Very simple :
>
> A server accept connections, a client does not.
>
> IoAcceptor contains a lot of logic to manage as many clients as possible. 
> IoConnector simply try to connect to a server.
>
>> Maybe question is what server don't know where data should be send.
> Certainly not. A server _always_ knows where to send the data : to a 
> client which has open a connection.
>
> In any case, the client initiate a communication with a server, and this 
> is how you distinguish between those two guys.
>
> To take a real life example : you are the client, because you posted this 
> mail to this mailing list, and I act as a server, replying to you 
> specifically. (the fact that it's a mailing list and that everybody can 
> read the post and the response is irrelevant : we are still communicating 
> together, from the semantic point of view)
>
> Did I replied to your question, or did I missed something ?
>
> -- 
> --
> cordialement, regards,
> Emmanuel Le'charny
> www.iktek.com
> directory.apache.org
>
>
> 



Re: MINA Clients and Servers

Posted by Emmanuel Lecharny <el...@apache.org>.
Sergey Mamitko wrote:
> Hello,
>
> What is REAL difference from communication point between MINA client (IoConnector) and server (IoAcceptor)
> They are both can send and receive data.
>   
Very simple :

A server accept connections, a client does not.

IoAcceptor contains a lot of logic to manage as many clients as 
possible. IoConnector simply try to connect to a server.

> Maybe question is what server don't know where data should be send. 
>   
Certainly not. A server _always_ knows where to send the data : to a 
client which has open a connection.

In any case, the client initiate a communication with a server, and this 
is how you distinguish between those two guys.

To take a real life example : you are the client, because you posted 
this mail to this mailing list, and I act as a server, replying to you 
specifically. (the fact that it's a mailing list and that everybody can 
read the post and the response is irrelevant : we are still 
communicating together, from the semantic point of view)

Did I replied to your question, or did I missed something ?

-- 
--
cordialement, regards,
Emmanuel Le'charny
www.iktek.com
directory.apache.org