简体   繁体   English

在Android中的本机代码和Java代码之间传输数据/数据包的最有效方法是什么

[英]What's the most efficient way to transfer data/packets between native code and Java code in Android

I'm going to write an Android App to read raw packet from native code with raw socket interface. 我将编写一个Android应用程序,以使用原始套接字接口从本机代码读取原始数据包。 My phone is rooted so my native code can access to the native code by using runtime.exec("su"). 我的手机已扎根,因此我的本机代码可以使用runtime.exec(“ su”)访问本机代码。 But I don't know how to efficient transfer packets between the native code and Java code. 但是我不知道如何在本机代码和Java代码之间高效地传输数据包。 (In this case, the native code and Java code are running in different processes) Since my App must process the raw packets from the native code as efficient as possible, I need a "fast tunnel" between them. (在这种情况下,本机代码和Java代码在不同的进程中运行)由于我的应用程序必须尽可能高效地处理本机代码中的原始数据包,因此我需要它们之间的“快速通道”。 Any ideas or suggestions? 有什么想法或建议吗?

PS I have tired Android NDK, but in NDK, native code and Java code are running in the same process so the native code cannot have the root privilege to access raw socket. PS:我对Android NDK感到厌倦,但是在NDK中,本机代码和Java代码在同一进程中运行,因此本机代码不能具有访问原始套接字的root特权。

The solution is: create an agent at native layer so that it can talk to your java activity via JNI. 解决方案是:在本机层创建一个代理,以便它可以通过JNI与您的Java活动对话。 Then hook up the agent and your native service by using IPC (binder). 然后使用IPC(活页夹)连接代理和本机服务。

One issue: it is not convenient to pass complex data structure via JNI. 一个问题:通过JNI传递复杂的数据结构并不方便。 So step back, why do you want to pass entire packets? 那么退后一步,为什么要传递整个数据包? Can you process the packets at native layer and submit the result (eg, integers) only? 您能否在本机层处理数据包并仅提交结果(例如整数)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 除了在 Java 中使用参数外,在方法调用之间传递数据的最有效方法是什么? - What is the most efficient way to pass data between method invocations except using parameters in Java? Android最有效的加密/解密连续UDP(语音数据包)数据的方法 - Android Most Efficient way for encrypting/decrypting continuous UDP (voice packets) data Android最有效的保存和加载图像的方法是什么? - Android what's the most efficient way to save and load images? 在Android中运行Cursor的最有效方法是什么? - What's the most efficient way to run over a Cursor in Android? 在XML中关联不同数据的最简单,最有效的方法是什么? - What's the simplest and most efficient way to associate different data in XML? Android上Java代码中最重要的优化是什么? - What are the most important optimizations in Java code on Android? Android:在本机代码(C)和应用程序(java)之间共享数据 - Android: Sharing data between native code (C) and application (java) 将 android 应用程序连接到网络服务器的最原生方式是什么? - What's the most native way to connect android app to a webserver? 在Android中显示表格的最有效方法是什么 - What is the most efficient way to display a table in Android 使用Android相机的最有效方法是什么? - What is the most efficient way to work with the Android camera?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM