server_addr.sin_port=htons(4044);//sometimes bind returns 0...means client will be connected...but with same code ...sometimes...bind returns -1...so client will not be connected..means port is still busy..in that case...we have to wait for 5 minutes..||2 min..or any much time || we have to change the port no. to make bind successfull....
//sleep(5);//after 5 sec...in server again i m writing from server to client...
printf("no1=%d no2=%d op=%c\n",no1,no2,op);
//write(client_fd,"hello",5);//writer will go on block..untill server writes to client again after 5 sec....means again...untill...there is no. reader ...writer will not write....||untill write does not write anything...reader will not read..MEANS reader will go on block....
//profd=socket(AF_INET,SOCK_STREAM,0);
profd=accept(fd,(struct sockaddr*)&pro_addr,&len);//copy of process socket is made here...the socket in which process has written data..that copy...of socket..that socket which is created by process...
printf("profd=%d\n",profd);//fd of a new socket for process will be retuned..
count=write(profd,&no1,4);//Means untill socket of some other system connnected to it,..||accept its request ||copy of this socket is created into other process..,,,it will not write into this socket....as
//fifo does not write untill reader is not there...but it is not stopping to read...it is reading..either no writer is there frm same fd...but if server has created a copy of this socket ...then that will not read untill...writer writes...........
printf("count write to pro1=%d\n",count);
count=write(profd,&no2,4);//write into process_fd ...so that process may read...
printf("count write to pro1=%d\n",count);//i know writer will not write anything untill there is no reader....but writer is not standing at block ..if u have not conneted to other socket....so if u r not connected to other socket ...this fd will neither perform any function nor go on block...at point of write statement..(if u r not connected)..after that it is leaving all the statements ..either it is printf.....
count=write(profd,&op,1);
printf("count write to pro1=%d\n",count);
count=read(profd,&res,4);//frm same fd result is also read
printf("RES IN SERVER=%d\n",res);
count=write(client_fd,&res,4);//in same fd of client result is written...which will be read in client
printf("count RESULT WRITTEN TO C1 *IN SERVER*=%d\n",count);
client_addr.sin_addr.s_addr=inet_addr("127.0.0.1");//loopback address...means for same system or p.c...try .................ifconfig..........,,,,,,,,command....
count=write(cfd,&opr,1);//reader of server will block ..untill writer not come into existence..& writer will not write untill reader does not came into existance..exectly same as fifo..no..matters..which process socket is binded or creating copy of other proces socket...which socket is created by other process.....mainly according to architecture of project binding of socket(giving name to socket ) is done in server...........
printf("count=%d\n",count);
//sleep(1);/result written by server into copy of this client's socket will come into this client's socket
fd=socket(AF_INET,SOCK_STREAM,0);//process socket is created here...means we have to operate..server 1st in which listen will make queue...in which no. of clients will wait..& accepted 1 by 1...server blocks at accept()...untill connect call is not done