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
