/** * Start server * * @return if server starts successfully, return true. */ @SuppressWarnings("unused") public boolean startServer() { try { serverSocket = new ServerSocket(serverPort); Log.i(TAG, "Create Server Socket at port " + serverPort); listeningThread.setServerSocket(serverSocket); listeningThread.start(); return true; } catch (IOException e) { Log.i(TAG, "Creating server failed"); e.printStackTrace(); return false; } }
/** * add public path * * @param path root path of public files */ @SuppressWarnings("unused") public void addPublic(String path) { File f = new File(path); if (!f.isDirectory()) { Log.e(TAG, path + " is not directory!!"); } else { publics.add(path); } }
/** Stop server */ @SuppressWarnings("unused") public void stopServer() { try { Log.i(TAG, "Stop Server"); if (serverSocket.isBound()) { serverSocket.close(); } } catch (IOException e) { e.printStackTrace(); } }
/** * Set server port * * @param port port */ @SuppressWarnings("unused") public void setPort(int port) { Log.i(TAG, "Set Port : " + port); this.serverPort = port; }