1、服务器端ser.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <assert.h>
5 #include <string.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <pthread.h>
10
11 //客户端服务器实现多线程
12 void* fun(void * arg)
13 {
14 int c = (int)arg;
15 while(1)
16 {
17 char buff[128] = {0};
18 int n = recv(c, buff, 127, 0);
19 if(n <= 0)
20 {
21 break;
22 }
23 printf("buff(%d)=%s\n",c,buff);
24 send(c, "ok", 2, 0);
25 }
26 printf("one client over\n");
27 close(c);
28 }
29
30 int main()
31 {
32 int sockfd = socket(AF_INET, SOCK_STREAM, 0);
33 assert(sockfd != -1);
34
35 struct sockaddr_in saddr, caddr;
36 me