Android Open Source - android-melogsta Socket I P C Server






From Project

Back to project page android-melogsta.

License

The source code is released under:

GNU General Public License

If you think the Android project android-melogsta 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 de.uvwxy.melogsta;
//from  www.j  a v a2 s.c  o  m
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import android.net.LocalServerSocket;
import android.net.LocalSocket;

public class SocketIPCServer implements Runnable {
  public static String SOCKET_ADDRESS_PREFIX = "/melogsta/";
  private LocalServerSocket server;
  private LocalSocket receiver;
  private boolean running = true;

  public SocketIPCServer(int pid) {
    try {
      server = new LocalServerSocket(SOCKET_ADDRESS_PREFIX + "" + pid);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public void stop() {
    running = false;
  }

  @Override
  public void run() {
    while (running) {
      DataInputStream input = null;
      try {
        receiver = server.accept();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (receiver != null) {
        int prio = -1;
        try {
          input = new DataInputStream(receiver.getInputStream());
          prio = input.readInt();

          ObjectOutputStream output = new ObjectOutputStream(receiver.getOutputStream());
          ArrayList<LogHistoryItem> logHistoryList = new ArrayList<LogHistoryItem>();
          Log.getLocalLog(prio, logHistoryList);
          output.writeObject(logHistoryList);

          input.close();
          output.close();
          receiver.close();
        } catch (IOException e) {
          e.printStackTrace();
        }

      }

    }

  }
}




Java Source Code List

de.uvwxy.melogsta.ActivityShowLogs.java
de.uvwxy.melogsta.LogHistoryItemArrayAdapter.java
de.uvwxy.melogsta.LogHistoryItem.java
de.uvwxy.melogsta.LogNotification.java
de.uvwxy.melogsta.LogTypeState.java
de.uvwxy.melogsta.Log.java
de.uvwxy.melogsta.SocketIPCClient.java
de.uvwxy.melogsta.SocketIPCServer.java