本文主要是介绍Android 与 native C 利用本地socket进行消息传递,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Android 与 native C 利用本地socket进行消息传递
Java源码:
// 服务器端
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.util.Log;public class SocketListener extends Thread {@Overridepublic void run() {Log.i(getClass().getName(), "run()");try {LocalServerSocket server = new LocalServerSocket("com.example.mysoftphone.localsocket");while (true) {LocalSocket receiver = server.accept();Log.i(getClass().getName(), "server.accept()");if (receiver != null) {InputStream input = receiver.getInputStream();InputStreamReader inputReader = new InputStreamReader(input); BufferedReader bufferReader = new BufferedReader(inputReader);String line = bufferReader.readLine();// String line1 = new String(line.getByt
这篇关于Android 与 native C 利用本地socket进行消息传递的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!