首页 > 代码库 > Android local socket学习总结
Android local socket学习总结
转载请注明出处: http://blog.csdn.net/xiexh0921/article/details/7513628
##############################################
目的:实现本地 C程序与apk的socket通信。
原理:没有涉及到网络通信,所以使用Android封装的local socket要更简单
参考:系统源码RIL模块
整理:Andy.xie
###############################################
C程序 服务端:
1) server_fd = socket_local_server (SOCKET_NAME_XXH,
C 客户端:ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);2) s_fdListen = listen(server_fd, 4);3) while((socket = accept(server_fd, NULL, NULL)) > 0)
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.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。