如何绑定到Android的一个端口小于1024? [英] How to bind to a port less than 1024 in Android?

查看:1851
本文介绍了如何绑定到Android的一个端口小于1024?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android服务试图绑定到服务器套接字端口24。由于它是特权端口,它失败了绑定异常。 我想知道什么,我需要做的就是这个工作。 我看到这个被问几次在这个论坛,但没有解决。

I have an Android service trying to bind to a server socket port 24. As it is privileged port, it is failing with a bind exception. I am wondering what I need to do to get this working. I see this was asked couple of times in this forum, but without a resolution.

该服务,在Android上运行的设备上运行。我们建立了设备android平台。我们有我们需要的全部控制权。

This service runs on a device that runs on Android. We build android platform for the device. We have all the control we need.

推荐答案

要绑定到一个端口低于1024,则需要以root身份,有这样做的两种方式。

To bind to a port less than 1024, you need to be root and there are two ways of doing that.

  1. 系统应用:从那里应当以root身份运行该应用程序应安装到/系统/ apps文件夹。不过,也有一些签名的问题,为此帮助<一个href="http://stackoverflow.com/questions/3635101/how-to-sign-android-app-with-system-signature">available.分布也与系统的应用程序有问题。

  1. System app : The app should be installed into /system/apps folder from where it shall be run as root. However, there are some signature issues for which help is available. Distribution is also a problem with system apps.

苏二进制:使用su二进制可以用一个简单的 EXEC(素-c [命令])被调用。但事情说起来容易,做起来难。您需要运行一个Android的过程不只是一个简单的命令。因此,有 libsuperuser 它为您提供的方法,并具有完整长度的文档页面

su binary : The su binary can be invoked using a simple exec("su -c [command]"). But things are easier said than done. You need to run an android processes not just a single command. Hence, there is libsuperuser which provides you the methods and has a full-length doc page.

这篇关于如何绑定到Android的一个端口小于1024?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆