Android local socket学习总结

 
##############################################
目的:实现本地 C程序与apk的socket通信。
原理:没有涉及到网络通信,所以使用Android封装的local socket要更简单
参考:系统源码RIL模块
整理:Andy.xie
###############################################
 

C程序 服务端:


        1)  server_fd = socket_local_server (SOCKET_NAME_XXH,
                ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
2)  s_fdListen = listen(server_fd, 4);
3)  while((socket = accept(server_fd, NULL, NULL)) > 0)
 
 
C 客户端:
 
        1)  fd = socket_local_client( SOCKET_NAME_XXH ,
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
        2)  write(fd, "hello", 5);
 
 
JAVA 客户端:
 
        1)  localSocket = new LocalSocket();
        2)  localSocket.connect(new LocalSocketAddress(socketAddress));
        3)  OutputStream os = localSocket.getOutputStream();
 
 
Namespace:
 
LocalSocketAddress.Namespace  ABSTRACT  A socket in the Linux abstract namespace   
LocalSocketAddress.Namespace  FILESYSTEM  A socket named with a normal filesystem path.  

LocalSocketAddress.Namespace  RESERVED  A socket in the Android reserved namespace in /dev/socket.

Android local socket学习总结,布布扣,bubuko.com

Android local socket学习总结

上一篇:[Android Pro] Android学习——在线查看android源代码的3种方式


下一篇:iOS开发备忘录:实现多StoryBoard之间跳转