多进程实现C/S
把上次的多进程简单的添加一个fork就可以实现一个简单的多进程服务器。具体进程创建和使用的函数,有时间得总结一下了~~~~
if(fork()==0){ char buffer[1024]; strcpy(buffer, "this is server! welcome!\n"); send(sock_client, buffer, 1024, 0); bzero(buffer,sizeof(buffer)); flag = recv(sock_client, buffer, 1024, 0); if(flag < 0){ perror("recv error!\n"); close(sock_serv); return; } printf("recv : %s\n",buffer); while(1){ bzero(buffer,sizeof(buffer)); flag = recv(sock_client, buffer, 1024, 0); if(flag < 0){ perror("recv error!\n"); close(sock_serv); return; } printf("i have recv buffer\n"); printf("recv : %s\n",buffer); if(strcmp(buffer,"quit") == 0){ printf("quit!!!\n"); break; } } }