https://blog.csdn.net/jiushimanya/article/details/82684525#commentBox
服务端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | int main() { //创建socket int sockfd = socket(PF_LOCAL,SOCK_DGRAM,0); if (sockfd == -1) perror ( "创建socket失败" ), exit (-1); //准备通信地址 struct sockaddr_un addr; addr.sun_family = PF_UNIX; strcpy (addr.sun_path, "a.sock" ); //绑定 intres=bind(sockfd, ( struct sockaddr*)&addr, sizeof (addr)); if (res==-1) perror ( "绑定失败" ), exit (-1); printf ( "绑定成功\n" ); //通信(用读写文件方式) charbuf[100]={}; read(sockfd,buf, sizeof (buf)); printf ( "收到信息:%s\n" ,buf); //关闭socket close(sockfd); return 0; } |
客户端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | int main() { int sockfd=socket(PF_LOCAL,SOCK_DGRAM,0); if (sockfd==-1) perror ( "创建socket失败" ), exit (-1); struct sockaddr_un addr; addr.sin_family=PF_UNIX; strcpy (addr.sun_path, "a.sock" ); //连接 int res=connect(sockfd,(structsockaddr*)&addr, sizeof (addr)); if (res==-1) perror ( "失败" ), exit (-1); printf ( "成功\n" ); write(sockfd, "Hello,Socket!" ,14); close(sockfd); return 0; } |
Android智能指针https://blog.csdn.net/luoshengyang/article/details/6786239
https://blog.csdn.net/u014783685/article/details/79977032
https://www.cnblogs.com/wuyepeng/p/9738093.html socket recv函数 和 send函数