3

I found some code on this link http://www.techbrainwave.com/?p=912 which describes how to set up a client server architecture using apache mina. However, in the example provided it is only one-way communication (from client to server). Does anyone know how to modify this in order to obtain two-way communication?

g90
  • 31
  • 1
  • 4

1 Answers1

5

If you want the server to reply to the client message, you need to do it in the IoHandler of the server :

@Override
public void messageReceived(IoSession session, Object message)
{
   logger.info("Message received in the server..");
   logger.info("Message is: " + message.toString());
   // reply to the client
   session.write( /*the reply message here */); 
}
Julien Vermillard
  • 2,945
  • 1
  • 18
  • 18
  • ok thanks that worked. I then tried to shift the client code to android (I'm using motodev). However, the program stumbles upon this line: IoConnector connector = new NioSocketConnector(); with the error : java.lang.NoClassDefFoundError: org.apache.mina.transport.socket.nio.Niosocketconnector. What do you think can be the cause? – g90 Apr 08 '11 at 12:47
  • it's another subject I think. You miss an import or a jar – Julien Vermillard Apr 11 '11 at 05:53