Android Open Source - mobile-chat Mina Chat Client Handler






From Project

Back to project page mobile-chat.

License

The source code is released under:

GNU General Public License

If you think the Android project mobile-chat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package br.com.etyllica.sonat.adapter.mina.client;
/*from w  w w  . ja v a  2s  .  c om*/
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

import br.com.etyllica.sonat.client.ClientListener;

public class MinaChatClientHandler extends IoHandlerAdapter {

  private ClientListener listener;

  private static final String COMMAND_USERS = "/users ";//whiteSpacing

  private static final String COMMAND_MESSAGE = "/msg ";//whiteSpacing

  public MinaChatClientHandler(ClientListener listener) {
    this.listener = listener;
  }

  @Override
  public void sessionOpened(IoSession session) {
    //session.write();
    System.out.println("I am connected");
  }

  @Override
  public void messageReceived(IoSession session, Object obj) {

    String msg = obj.toString();

    if(msg.startsWith(COMMAND_USERS)) {

      String[] names = msg.substring(COMMAND_USERS.length()).split(" "); 

      listener.updateNames(names);

    } else if (msg.startsWith(COMMAND_MESSAGE)) {

      String message = msg.substring(COMMAND_MESSAGE.length());

      String[] parts = msg.split(" ");

      String userName = parts[1];

      message = message.substring(userName.length()+" ".length());

      listener.receiveMessage(userName, message);

    }

  }

  @Override
  public void exceptionCaught(IoSession session, Throwable cause) {
    session.close();
  }

}




Java Source Code List

br.com.etyllica.mobile.gui.HorizontalRule.java
br.com.etyllica.sonat.adapter.mina.client.MinaChatClientHandler.java
br.com.etyllica.sonat.adapter.mina.client.MinaClient.java
br.com.etyllica.sonat.adapter.mina.server.MinaChatServerHandler.java
br.com.etyllica.sonat.adapter.mina.server.MinaServer.java
br.com.etyllica.sonat.chat.ChatServerHandler.java
br.com.etyllica.sonat.client.ClientImpl.java
br.com.etyllica.sonat.client.ClientListener.java
br.com.etyllica.sonat.client.Client.java
br.com.etyllica.sonat.server.ServerHandler.java
br.com.etyllica.sonat.server.ServerImpl.java
br.com.etyllica.sonat.server.Server.java
br.unirio.livechat.ChatActivity.java
br.unirio.livechat.LoginActivity.java
br.unirio.livechat.ServerActivity.java