3 ms·
You can't bind to ports so you can't run a server without a proxy. Depending on your android version you also can't run containers due to missing kernel syscall
by alightsoul 3mo ago
You can't bind to ports so you can't run a server without a proxy. Depending on your android version you also can't run containers due to missing kernel syscalls, so you have to use x86 emulation
- pjmlp 3mo agoHere is a secret, you don't need containers for server software, we have been doing it for decades. Yes there are ways to bind to server ports with official APIs, example can be requested to Fable, Claude, or whoever you feel like it.
- alightsoul 3mo agoWhat do you mean? Android blocks apps from binding to ports which is what apache httpd does unless you root. I would be asking Claude for an exploit to unlock the bootloader so I can root Also, you can't install things on termux if you have android 6 or below. You must install postmarketos and thus an unlocked bootloader.
- pjmlp 3mo agoNot if the application has the right permissions on their installation manifest. <uses-permission android:name="android.permission.INTERNET" /> Then you need to write the server handling code on a background application thread, with perfectly working server sockets. This only works on wlan, or local network when using bluethooth, but who wants data modem for a server anyway. With Gemini's compliment, import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.BufferedReader import java.io.InputStreamReader import java.net.ServerSocket import java.net.Socket import java.net.SocketException class AndroidTcpServer { private var serverSocket: ServerSocket? = null private var isRunning = false // Call this function from a CoroutineScope (e.g., lifecycleScope.launch) async suspend fun startServer(port: Int = 8080) { withContext(Dispatchers.IO) { try { serverSocket = ServerSocket(port) isRunning = true // Loop to continuously accept incoming client connections while (isRunning) { val clientSocket = serverSocket?.accept() // Blocks until a client connects if (clientSocket != null) { // Handle each client connection in a separate background routine handleClient(clientSocket) } } } catch (e: SocketException) { // Triggered when stopServer() closes the socket println("Server socket closed: ${e.message}") } catch (e: Exception) { e.printStackTrace() } finally { stopServer() } } } private suspend fun handleClient(socket: Socket) { withContext(Dispatchers.IO) { try { val reader = BufferedReader(InputStreamReader(socket.getInputStream())) val outputStream = socket.getOutputStream() // Read incoming text from client val incomingMessage = reader.readLine() println("Received from client: $incomingMessage") // Send a simple response back to the client val response = "Hello from Android Server!\n" outputStream.write(response.toByteArray()) outputStream.flush() } catch (e: Exception) { e.printStackTrace() } finally { // Always close individual client connections socket.close() } } } fun stopServer() { isRunning = false try { serverSocket?.close() } catch (e: Exception) { e.printStackTrace() } } } As you might imagine by my comment history, I am a big fan of letting Android be Android, with Android native apps, not stuffing GNU/Linux into an APK.
- Denatonium 2mo agoYou can bind ports 1024-65535, and if you're in a home setting, you can just configure the port forwarding/DNAT settings on your home router to forward external ports 80/443 to whatever ports you're using internally. Containers are nice, but they're not strictly necessary. On Google Pixel 6 and newer phones, you can take it a step further and root your phone and run a KVM-accellerated arm64 Linux virtual machine on your phone. There's a port of Limbo PC emulator that includes support for the KVM accelleration, and it works quite well! It even allows you to pass through USB devices to the guest.
- alightsoul 2mo agoSo I would need to buy a new separate router and connect it to my ISP's router.
- Denatonium 2mo agoDoes your ISP router not allow you forward a port to a different port? I just assumed that was just a basic feature that any router would have. If the ISP router is that bad, it's definitely time to replace the ISP router or put in into bridge mode.