bret = bind(sockfd,(struct sockaddr *)&server_add,sizeof(struct sockaddr));/* it gives the name to created socket*/ printf("bind return %d\n",bret); if(bret==-1) { printf("error in binding"); }
listen(sockfd,3);/* it create waiting queue for upcoming request on socket and set limit */
len = sizeof(client_add); //printf("len %d\n",*len); aret = accept(sockfd,(struct sockaddr *)&client_add,&len);/* it is the blocking point for the request & it return temp fd for client*/ printf("accept return %d\n",aret); /*--------------------------------- thread for read operation by requesting client-----------------------*/ printf("hi\n"); int th_ret; th_ret = pthread_create(&th,NULL,p_threadfun,(void *) &aret); printf("th_ret %d",th_ret); pthread_join(th,&rl); printf("exit code of thread=%s",(char *)rl); /*read(aret,ch,5); printf("SERVER:%s\n",ch);*/ return 0; }
void * p_threadfun(void * mesg) { int *a, res1; char ch[5]; struct data { char a; int b; int c; }d; printf("aret=%d",aret); a = (int *)mesg; read(*a,&d,sizeof(struct data));
printf("data is %c ,%d,%d\n",d.a,d.b,d.c); int p_sockfd,true,bret;
bret = bind(p_sockfd,(struct sockaddr *)&p_server_add,sizeof(struct sockaddr));/* it gives the name to created socket*/ printf("bind return %d\n",bret); if(bret==-1) { printf("error in binding"); }
listen(p_sockfd,3);/* it create waiting queue for upcoming request on socket and set limit */
len = sizeof(p_client_add); //printf("len %d\n",*len); aret = accept(p_sockfd,(struct sockaddr *)&p_client_add,&len);/* it is the blocking point for the request & it return temp fd for client*/ printf("accept return %d\n",aret); write(aret,&d,sizeof(struct data)); read(aret,&res1,4);
printf("result is %d\n",res1); pthread_exit("poonam"); }