Apache Directory Project - [mina] Create a client and server implementation

This is Interesting: Free IT Magazines  
Home > Archive > Apache Directory Project > November 2005 > [mina] Create a client and server implementation





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [mina] Create a client and server implementation
Shay Banon

2005-11-30, 5:45 pm

Hi,

I wish to use mina in order to create both a server and a client. I
have problems with the client part, basically, the client connects to
the server (has a session), and within the session executes several
operations, which are synchronous (i.e. send a message, and wait for a
reply). The server, has the corresponding session, receives the client
operations, and sends back the response.

I was thinking of using my own codec to define the operations and
the data (similar to the sumup example). The server side will probably
be similar to the sumup example as well. I have several questions:

1. Can I use the mina concept of a session (using the session handler)
to maintain the my session? I am guessing that the client and server
have the same session in mina.
2. How can I program the client code to be operation based and
synchronous (similar to RMI)? On the server side, I can process the
operation in the messageReceived, and send the respond in it (similar to
the sumup server), but I do not know how to do that in the client.

Thanks for your help.

Shay Banon
http://www.compassframework.org


Niklas Therning

2005-11-30, 5:45 pm



Shay Banon wrote:
> Hi,
>
> I wish to use mina in order to create both a server and a client. I
> have problems with the client part, basically, the client connects to
> the server (has a session), and within the session executes several
> operations, which are synchronous (i.e. send a message, and wait for a
> reply). The server, has the corresponding session, receives the client
> operations, and sends back the response.
>
> I was thinking of using my own codec to define the operations and the
> data (similar to the sumup example). The server side will probably be
> similar to the sumup example as well. I have several questions:
>
> 1. Can I use the mina concept of a session (using the session handler)
> to maintain the my session? I am guessing that the client and server
> have the same session in mina.


In MINA an IoSession corresponds to a connection, sort of like a Socket.
So if you need to maintain state on a per connection basis the
IoSession is a good place to put that state (probably by using the
setAttribute()/getAttribute() methods). MINA maintains the IoSessions
and makes sure the correct callbacks are called in your IoHandler
implementation. All you have to care about is maintaining the
per-connection state if needed.

I'm not sure what you mean by "the client and server have the same
session in mina". There is a 1:1 correspondence between the client side
IoSession and server side IoSession if that's what you mean.

> 2. How can I program the client code to be operation based and
> synchronous (similar to RMI)? On the server side, I can process the
> operation in the messageReceived, and send the respond in it (similar to
> the sumup server), but I do not know how to do that in the client.


The client side is no different from the server side. When you call
connector.connect() you supply an IoHandler, just like you do when you
call bind() on the server side. You will probably have one
ClientIoHandler class which implements the client side of your protocol
and one ServerIoHandler class which implements the server side.

If you wish to do completely synchronous IO on the client side (one
thread per client) it can be done but maybe it would be simpler to use
plain old Socket for that?

BTW, what version of MINA are you using? 0.8 or 0.9?

Please let me know if you have any further questions.
/Niklas

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com