{"id":48680797,"url":"https://github.com/joanpuigsanz/servdroid","last_synced_at":"2026-04-26T20:00:41.535Z","repository":{"id":9669942,"uuid":"11611483","full_name":"joanpuigsanz/servdroid","owner":"joanpuigsanz","description":"Small Web server for Android","archived":false,"fork":false,"pushed_at":"2015-11-22T23:33:01.000Z","size":2804,"stargazers_count":101,"open_issues_count":4,"forks_count":56,"subscribers_count":17,"default_branch":"master","last_synced_at":"2023-11-07T21:13:11.538Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joanpuigsanz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-23T15:13:08.000Z","updated_at":"2023-11-03T15:23:20.000Z","dependencies_parsed_at":"2022-09-01T07:12:35.467Z","dependency_job_id":null,"html_url":"https://github.com/joanpuigsanz/servdroid","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"purl":"pkg:github/joanpuigsanz/servdroid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanpuigsanz%2Fservdroid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanpuigsanz%2Fservdroid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanpuigsanz%2Fservdroid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanpuigsanz%2Fservdroid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joanpuigsanz","download_url":"https://codeload.github.com/joanpuigsanz/servdroid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joanpuigsanz%2Fservdroid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32310804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T19:15:34.056Z","status":"ssl_error","status_checked_at":"2026-04-26T19:15:15.467Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-11T01:00:36.065Z","updated_at":"2026-04-26T20:00:41.530Z","avatar_url":"https://github.com/joanpuigsanz.png","language":"Java","funding_links":[],"categories":["网络编程"],"sub_categories":["Spring Cloud框架"],"readme":"ServDroid\n=========\n\nServDroid is an small web server for the Android platform.\n\n* Auto start options\n* Can run under port 1024 (iptables and super user rights are required). Check the [wiki](https://github.com/joanpuigsanz/servdroid/wiki/Use-port-under-1024) for more information\n* Only serves HTML pages (Servlets implementations will be considered for in future versions).\n* Log of all requests are saved in the Android database. This information can be dumped to a text file.\n* ServDroid can be configured to vibrate when a request is received.\n* The 404 error page can be personalised.\nAvailable on [Google Play store](https://play.google.com/store/apps/details?id=org.servDroid.web)\n\nThis project uses ActionBarSherlock. In order to be able to use it run the following commands on the root project path:\n```\ngit submodule init\ngit submodule update\n```\n## Binding the ServDroid service\nThe version 0.2.4 and above allows the developer to manage the ServDroid service from an other application. \n\nIf you have an application which needs to manage a web server you can use the ServDroid for this purpose.\nIn this page you will learn how to connect to the ServDroid service in order to manage through using a simple helper.\n\n![Screenshots](http://joanpuigsanz.github.io/servdroid/images/servdroid_screens.png) \n\n### How to\nYou can find a simple example in the ServDroid repository\n\nFirst you need to copy the following files to your project:\n\n* org.servDroid.db.LogMessage.java\n* org.servDroid.db.LogMessage.aidl\n* org.servDroid.helper\n* org.servDroid.helper.IServiceHelper.java\n* org.servDroid.helper.ServiceHelper.java\n* org.servDroid.server.service\n* org.servDroid.server.service.params\n* org.servDroid.server.service.ServerValues.java\n* org.servDroid.server.service.ServiceController.aidl\n\nYou also can take them from the example code in the repo. (just copy the whole org.servDroid package from the example project)\n\nThen prepare your manifest adding this lines:\n\n```xml\n\u003cservice android:name=\"org.servDroid.server.service.ServerService\"\u003e\n      \u003cintent-filter\u003e\n        \u003caction android:name=\"org.servDroid.server.service.ServiceController\" /\u003e\n      \u003c/intent-filter\u003e\n\u003c/service\u003e\n```\nWe need to create the ServiceHelper instance in onCreate\n\n```java\n@Override\npublic void onCreate(Bundle savedInstanceState) {\n      super.onCreate(savedInstanceState);\n      mServiceHelper = new ServiceHelper(this);\n      // We can change the periodicity of getting status change notifications\n      //mServiceHelper.setStatusTimeRefresh(2500);\n}\n```\nConnect the instance to the service and disconnect it when it is not needed any more\n\n```java\n@Override\nprotected void onResume() {\n      ...\n      mServiceHelper.connect();\n      // We also can run code when the service is  binded:\n      // mServiceHelper.connect(myRunnable);\n      super.onResume();\n}\n\n@Override\nprotected void onPause() {\n      ...\n      mServiceHelper.disconnect();\n      super.onPause();\n}\n```\n\nNow we have our helper binded with the service, so we can work with the server.\n```java\nstatus = mServiceHelper.getServiceController().getStatus();\nif (status == ServerValues.STATUS_RUNNING) {\n      mServiceHelper.getServiceController().stopService();\n} else if (status == ServerValues.STATUS_STOPPED) {\n      ServerParams params = new ServerParams(\"/sdcard/\", \"/sdcard/error\", 30, true, 8080, 10);\n      mServiceHelper.startServer(params);\n}\n```\n\n### Getting status notifications.\n\nIf you want to get notifications when the status of the server changes you can register your own listener. Just remember to unregister it when you will not need it anymore\n\n```java\n@Override\nprotected void onResume() {\n      // Register a listener to get notified when the status changes\n      mServiceHelper.addServerStatusListener(this);\n      mServiceHelper.connect();\n      ...\n}\n\n@Override\nprotected void onPause() {\n      // Before disconnect, remove the status listener\n      mServiceHelper.removeServerStatusListener(this);\n      mServiceHelper.disconnect();\n      ...\n}\n```\nAnd finally, just get the status events and manage them as you need\n\n```java\n@Override\npublic void onServerStatusChanged(ServiceController serviceController, int status) {\n      switch (status) {\n      case IServiceHelper.STATUS_CONNECTED:\n            // Create a log line to append to the ServDroid logs\n            LogMessage logLine = new LogMessage();\n            logLine.setInfoEnd(\"Service linked succesfull from an external application\");\n            logLine.setTimeStamp(System.currentTimeMillis());\n            try {\n                  // Send the line\n                  mServiceHelper.getServiceController().addLog(logLine);\n            } catch (RemoteException e) {\n                  e.printStackTrace();\n            }\n            updateStatusText(\"Status: Connected\");\n            break;\n      case IServiceHelper.STATUS_DISCONNECTED:\n            updateStatusText(\"Status: Disconnected\");\n            break;\n      case IServiceHelper.STATUS_STOPPED:\n            updateStatusText(\"Status: Connected / Server stopped\");\n            break;\n      case IServiceHelper.STATUS_RUNNING:\n            updateStatusText(\"Status: Connected / Server running\");\n            break;\n      default:\n            break;\n      }\n}\n```\n### Doing other stuff with the service\nIf you want to access directly the instance that is connected to the service it is possible to get it using the helper:\n```java\nServiceController serviceController = mServiceHelper.getServiceController();\n```\n\nThe available functions are documented in the file org.servDroid.server.service.ServiceController.aidl:\n* startService()\n* restartService()\n* stopService()\n* getStatus()\n* getCurrentParams()\n* getDefaultPortOnRoot()\n* getVersion()\n* addLog()\n* getLogList()\n\n```java\n/**\n * Start the server with the defined parameters\n *\n * @param params\n *      The parameter with the configuration of the server\n *\n * @return True if the server has been initialized, false otherwise\n */\nboolean startService(in ServerParams params);\n\n/**\n * Restart the server with the defined parameters\n *\n * @param params\n *      The parameter with the configuration of the server\n *\n * @return True if the server has been initialized, false otherwise\n */\nboolean restartService(in ServerParams params);\n\n /**\n * Stop the server.\n *\n * @return True if the server has been stopped, false otherwise\n */\nboolean stopService(); \n\n/**\n * Get the status of the server:\u003cbr\u003e\n * {@link ServerValues.STATUS_RUNNING} The server is running \u003cbr\u003e\n * {@link ServerValues.STATUS_STOPED} The server is stopped \u003cbr\u003e\n *\n * @return True if the server has been initialized, false otherwise\n */\nint getStatus();\n\n\n/**\n * Get the parameters in use by the server.\n * @return The  {@link ServerParams} in use for the server\n */\nServerParams getCurrentParams();\n\n /**\n * This is the default port opened when the user ask for opening a port\n * under 1024. \u003cbr\u003e\n * The system will try to use iptables like this:\u003cbr\u003e\n * iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port\n * DEFAULT_PORT_ON_ROOT\n * @return The default port when the root permissions are required.\n */\nint getDefaultPortOnRoot();\n\n/**\n * Use this function to enable and disable the vibrations\n * when a request is received.\n * @param params \n *   True to vibrate if a petition is accepted, false otherwise.\n */\nvoid setVibrate(in boolean vibrate);\n\n/**\n * Get the servDroid software version\n * @return The ServDroid.web version\n */\nString getVersion();\n\n/**\n * Create a new log entry using the the IP, request path, some extra\n * information. If the log is added successfully return the new rowId for\n * that log entry, otherwise return a -1 to indicate failure.\n * \n * @param msg\n *            The message to be stored in the log\n\n * @return rowId or -1 if failed\n */\nlong addLog(in LogMessage msg);\n\n/**\n * Return the ArrayList which contains the log list\n * \n * @param numRows\n *            The number of rows to get\n * \n * @return List with the log entries\n */\nList\u003cLogMessage\u003e getLogList(in int numRows);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanpuigsanz%2Fservdroid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoanpuigsanz%2Fservdroid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanpuigsanz%2Fservdroid/lists"}