Android Open Source - mobile-chat Mina Client






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 ww .ja v  a  2  s .  c o  m*/
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

import br.com.etyllica.sonat.client.Client;
import br.com.etyllica.sonat.client.ClientImpl;

public class MinaClient extends ClientImpl implements Client {

  private IoConnector connector;
  
  private IoSession session;
  
  public MinaClient(String host, int port) {
    super(host, port);
  }

  public void init() {
    
    IoConnector connector = new NioSocketConnector();
    connector.getSessionConfig().setReadBufferSize(2048);

    connector.getFilterChain().addLast("logger", new LoggingFilter());
    connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));

    connector.setHandler(new MinaChatClientHandler(listener));
    
    ConnectFuture future = connector.connect(new InetSocketAddress(host, port));
    future.awaitUninterruptibly();

    if (!future.isConnected()) {
      return;
    }
    
    session = future.getSession();
    
  }
  
  public void finish() {
    connector.dispose();
  }

  @Override
  public void sendMessage(String message) {
    session.write(message);
  }

}




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