socket通信可以直接传送结构体! 示例: (发送端) struct student { char name[20]; int age; }; struct student student1={"liuxiaobing",23}; 接受端: struct student { char name[20]; int age; }; struct student *student_client = NULL; while(1) { n = read(sockfd, recvline, MAXLINE); if(n == -1) { perror("read error"); exit(1); } student_client = (struct student *)recvline; //recvline[n] = 0; printf("Receive:name=%s***age=%d/n",student_client->name,student_client->age); //fputs(recvline, stdout); //printf("%s/n",recvline); } UDPsocket通信简单的代码: udpserv.c /*udpserv.c*/ #include <sys/types.h> #include <sys/socket.h