CanPHP框架技术讨论

导航

 
 
##############################################
目的:实现本地 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.

posted on 2014-08-22 11:39  創丗仼  阅读(1831)  评论(0编辑  收藏  举报