public void stop() { if (destroyed) { return; } destroyed = true; count--; if (count == 0) { stopServicesMDNS(); service.stopSelf(); } thread.interrupt(); try { serverSocket.close(); } catch (IOException ex) { Log.e(TAG, "", ex); } Log.i(TAG, "Server " + addr.getHostName() + " stopped"); }