Android Open Source - ZShaolin webserver






From Project

Back to project page ZShaolin.

License

The source code is released under:

GNU General Public License

If you think the Android project ZShaolin 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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.//from   ww w.ja v  a2 s  .  c om
 */

package com.spartacusrex.spartacuside.web;

import android.content.Context;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
import java.util.Vector;
import javax.net.ServerSocketFactory;

/**
 *
 * @author Spartacus Rex
 */
public class webserver implements Runnable{

    Thread mMainThread;
    boolean mRunning;
    
    ServerSocket mMainServer;
    sockethandler mLastHandler;
    
    Context mContext;

    Vector  mHandlers;
    boolean mStopMode = false;

    
    public webserver(Context zContext){
        mContext    = zContext;
        mHandlers = new Vector();
        mStopMode = false;
    }

    public void log(String zLog){
        Log.v("SpartacusRex", "AppServer - "+zLog);
    }

    public void start(){
        log("START THE WEBSERVER!!!");
        mRunning    = true;
        mMainThread = new Thread(this);
        mMainThread.start();
    }

    public void stop(){
        log("WEBSERVER STOPPING");
        mStopMode = true;
        if(mMainServer!=null){
            try {
                if(!mMainServer.isClosed()){
                    mMainServer.close();
                }
            } catch (IOException iOException) {
                log("server stop - "+iOException.toString());
            }

            //Stop all the socket handlers
            for(Enumeration e=mHandlers.elements();e.hasMoreElements();){
                sockethandler handler = (sockethandler)e.nextElement();
                handler.stop();
            }
        }

        mRunning = false;
        mMainThread.interrupt();
    }

    public void run() {
        log("Server Started");

        mMainServer = null;
        Socket sock = null;
        try {
            //Open a socket..
            mMainServer = ServerSocketFactory.getDefault().createServerSocket(10000);
            mMainServer.setSoTimeout(0);

            while(mRunning){
                sock = mMainServer.accept();
                sock.setSoTimeout(0);
                sock.setTcpNoDelay(true);
                
                log("Client accepted");
                if(mLastHandler != null){
                   mLastHandler.stop();
                }
                sockethandler handler = new sockethandler(sock,mContext,this);
                mLastHandler = handler;
            
                //Add to our list
                mHandlers.add(handler);
            }

        }catch (Exception iOException) {
            log("Client accept "+iOException.toString());
            
        }

        try {
            if(mMainServer!=null){
                if(!mMainServer.isClosed()){
                    mMainServer.close();
                }
            }
        } catch (IOException iOException1) {
            log("internal - "+iOException1.toString());
        }

        log("Server finished");
    }

    public void sockethandlerFinished(sockethandler zHandler){
        if(!mStopMode){
            mHandlers.remove(zHandler);
        }
    }
}




Java Source Code List

com.spartacusrex.spartacuside.EmulatorView.java
com.spartacusrex.spartacuside.Exec.java
com.spartacusrex.spartacuside.TermDebug.java
com.spartacusrex.spartacuside.TermPreferences.java
com.spartacusrex.spartacuside.TermService.java
com.spartacusrex.spartacuside.TermViewFlipper.java
com.spartacusrex.spartacuside.Term.java
com.spartacusrex.spartacuside.WindowList.java
com.spartacusrex.spartacuside.keyboard.CandidateView.java
com.spartacusrex.spartacuside.keyboard.KeyboardPrefs.java
com.spartacusrex.spartacuside.keyboard.KeyboardSwitcher.java
com.spartacusrex.spartacuside.keyboard.LatinKeyboardView.java
com.spartacusrex.spartacuside.keyboard.LatinKeyboard.java
com.spartacusrex.spartacuside.keyboard.MyKeyboardView.java
com.spartacusrex.spartacuside.keyboard.TerminalKeyboard.java
com.spartacusrex.spartacuside.model.Screen.java
com.spartacusrex.spartacuside.model.TextRenderer.java
com.spartacusrex.spartacuside.model.UpdateCallback.java
com.spartacusrex.spartacuside.session.TermSession.java
com.spartacusrex.spartacuside.session.TerminalEmulator.java
com.spartacusrex.spartacuside.session.TranscriptScreen.java
com.spartacusrex.spartacuside.util.ByteQueue.java
com.spartacusrex.spartacuside.util.ServiceForegroundCompat.java
com.spartacusrex.spartacuside.util.TermSettings.java
com.spartacusrex.spartacuside.util.dialogpref.java
com.spartacusrex.spartacuside.util.hardkeymappings.java
com.spartacusrex.spartacuside.util.keydata.java
com.spartacusrex.spartacuside.web.sockethandler.java
com.spartacusrex.spartacuside.web.webserver.java
org.dyne.zshaolin.Start.java
org.dyne.zshaolin.startup.TerminalIDEPrefs.java
org.dyne.zshaolin.startup.setup.assetextract.java
org.dyne.zshaolin.startup.setup.filemanager.java
org.dyne.zshaolin.startup.installer.java
org.dyne.zshaolin.startup.introscreen.java