static int sockfd;
static int ss;
void sig_exit(int signo){
close(sockfd);
printf("exit!\n");
exit(0);
}
void* Pthread_client(void* fd){
int i;
int sfd=*(int*)fd;
char buff[10] = {0};
char buf[1024]={1};
if(read(sfd, buff, sizeof(buf))> 0)
for(i=0; i
}
int main(int argc , char* argv[]){
signal(SIGINT,sig_exit);
printf("take Ctrl+C to exit!");
ss=atoi(argv[1]);
//creat socket
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if(sockfd == -1)perror("create socket failed!"),exit(-1);
//address
struct sockaddr_in addr;
addr.sin_family = PF_INET;
addr.sin_port = htons(7000);
addr.sin_addr.s_addr = INADDR_ANY;
//bind
int ret=bind(sockfd,(struct sockaddr*)&addr,sizeof(addr));
if(ret == -1)perror("bind error!"),exit(-1);
//listen
if(listen(sockfd, 100) == -1)
perror("listen error!"),exit(-1);
//wait client
while(1){
struct sockaddr_in fromaddr;
socklen_t len = sizeof(fromaddr);
int fd = accept(sockfd, (struct sockaddr*)&fromaddr,&len);
if(fd == -1)perror("accept error!"),exit(-1);
pthread_t id;
pthread_create(&id,0,Pthread_client,(void*)&fd);
}
pause();
return 0;
}