zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    JNUOJ 1187
    JNUOJ 1184
    HDU 4848
    HDU 4849
    哈夫曼树和哈弗曼编码小记
    HDU 5726
    POJ 3368 & UVA 11235
    2016江苏省CPC省赛 I
    POJ 3928
    POJ 3067
  • 原文地址:https://www.cnblogs.com/canphp/p/3929038.html
Copyright © 2011-2022 走看看